Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Metaclass is not properly inherited when using multiple inheritance with int #2824
class M(type): def foo(self): pass class C(metaclass=M): pass print(C.__class__) C.foo() class D(int, C): pass print(D.__class__) D.foo()
Running this with Python 3 shows that D's metaclass is M, but when checking this with mypy, we get the error
on the last line, showing that mypy doesn't believe so.
This seems unique to
FWIW this prevents me from fixing #2305 (iterating on enums) -- I can get it to work for Enum but not for IntEnum, because it multiply inherits from int and from Enum.
Without that I get
FWIW the test program is
import enum class E(enum.Enum): a = 1 b = 2 for i in E: reveal_type(i) class I(enum.IntEnum): a = 1 b = 2 for k in I: reveal_type(k)
and its output (less the error) is
which is exactly what it should be.
There are additional checks to add to the subtype visitor that makes this problem go away, but something bothers me. The variable seems to be overly constrained by a class not defined yet. We should add another check for the metaclass declaration, to verify that we are constrained correctly by the type of cls.
As I have mentioned in a different discussion here, it might make sense to use the form