Skip to content

Metaclass is not properly inherited when using multiple inheritance with int #2824

Closed
python/typeshed
#1598
@gvanrossum

Description

@gvanrossum

Consider:

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

u.py:10: error: "D" has no attribute "foo"

on the last line, showing that mypy doesn't believe so.

This seems unique to int (or perhaps builtin types?) -- when create a separate class A (without a metaclass) and use that instead of int, there is no error.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions