Skip to content

Mypy does not detect metaclass conflicts #13563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sobolevn opened this issue Aug 31, 2022 · 0 comments
Closed

Mypy does not detect metaclass conflicts #13563

sobolevn opened this issue Aug 31, 2022 · 0 comments
Assignees
Labels
bug mypy got something wrong topic-metaclasses

Comments

@sobolevn
Copy link
Member

sobolevn commented Aug 31, 2022

Minimal reproducer:

class MyMeta1(type): ...
class MyMeta2(type): ...
class A(metaclass=MyMeta1): ...
class B(metaclass=MyMeta2): ...
class C(A, B): ...

In runtime it causes:

» python ex.py
Traceback (most recent call last):
  File "ex.py", line 5, in <module>
    class C(A, B): ...
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

But, mypy is fine with it:

» mypy ex.py --strict
Success: no issues found in 1 source file

Important note: I think this should only work outside of stubs, because we do some extra metaclass hackery (like ABCMeta) in stubs. Moreover, in stubs - it won't raise.

Related #13561

@sobolevn sobolevn added bug mypy got something wrong topic-metaclasses labels Aug 31, 2022
@sobolevn sobolevn self-assigned this Aug 31, 2022
sobolevn added a commit to sobolevn/mypy that referenced this issue Aug 31, 2022
sobolevn added a commit to sobolevn/mypy that referenced this issue Sep 3, 2022
sobolevn added a commit to sobolevn/mypy that referenced this issue Sep 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-metaclasses
Projects
None yet
Development

No branches or pull requests

1 participant