Right now there's an inconsistency in how base classes / metaclasses behave when working with Any.
Example:
fromtypingimportAnyMyAny: Any=type('MyAny', (type,), {'a': 1})
classSubclass(MyAny):
passclassWithMeta(metaclass=MyAny):
passreveal_type(Subclass.a) # N: Revealed type is "Any"reveal_type(WithMeta.a) # E: "Type[WithMeta]" has no attribute "a" \# N: Revealed type is "Any"Both Subclass.a and WithMeta.a return 1 in runtime. But, for some reason metaclass=Any is not recognised.
It even has an existing TODO item:
| ifisinstance(sym.node, Var) andisinstance(get_proper_type(sym.node.type), AnyType): |
| # 'Any' metaclass -- just ignore it. |
| # |
| # TODO: A better approach would be to record this information |
| # and assume that the type object supports arbitrary |
| # attributes, similar to an 'Any' base class. |
| returnNone, False |
But, it was never implemented. I would love to fix it.
Related:
Right now there's an inconsistency in how base classes / metaclasses behave when working with
Any.Example:
Both
Subclass.aandWithMeta.areturn1in runtime. But, for some reasonmetaclass=Anyis not recognised.It even has an existing
TODOitem:mypy/mypy/semanal.py
Lines 2076 to 2082 in dfbaff7
But, it was never implemented. I would love to fix it.
Related: