Open AlexWaygood opened 2 years ago
The issue seems to be that the call to is_subtype_helper
here returns False
, whereas for a class without a metaclass, it returns True
: https://github.com/python/mypy/blob/d27bff62f71a8b914b1df239467148e81d2e88a2/mypy/stubtest.py#L887
So the question is_subtype_helper
gets posed is whether Meta
is a subtype of type[Y]
. This fails for the same reason that mypy will complain about x: type[Y] = Meta
. The fix is probably some change in get_mypy_type_of_runtime_value
— we currently always make Instance
s, but maybe we should have some complicated logic that comes up with TypeType
for metaclasses? Might be a little tricky to get heuristics right, but subclass of type
is hopefully good enough
Bug Report
Given a stub like so:
And a runtime like so:
Stubtest will issue the following complaint:
This error can be reproduced with any custom metaclass; it's not just
ABCMeta
that triggers the bug:To Reproduce
Check out a local clone of mypy
Activate a virtual environment with an editable install of mypy
Apply this diff:
Run
pytest ./mypy/test/teststubtest.py
Expected Behavior
No error should be emitted.
Actual Behavior
An error was emitted.
Cc. @hauntsaninja