The typing.get_type_hints
function doesn’t find annotations for attributes inherited from metaclasses, unlike attributes inherited from ordinary classes:
>>> class Meta(type):
... x: int = 42
...
>>> class Base(metaclass=Meta):
... y: float = 3.14
...
>>> Base.x
42
>>> import typing
>>> typing.get_type_hints(Base)
{'y': <class 'float'>}
Is there a reason for this behavior?
Also, is the procedure for looking up attributes of a class described in full somewhere in the documentation? None of the references I could find explicitly mention the possibility of finding the attribute on the metaclass, and the metaclass isn’t included in the class’s MRO, so it’s not clear what the behavior is supposed to be. (If I understand the CPython implementation correctly, when there are no descriptors involved the search order is the MRO of the class first, followed by the MRO of its metaclass.)