Skip to content

ABCMeta and its subclasses are treated differently #13561

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 · Fixed by #13562
Closed

ABCMeta and its subclasses are treated differently #13561

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

Comments

@sobolevn
Copy link
Member

It is a common practice to create subclasses of ABCMeta for your own abstract metaclasses when you also have other metaclass(es). It helps solving metaclass conflict error.

For example:

from djang.db.models import ModelBase
from abc import ABCMeta

class AbstractModel(ABCMeta, ModelBase): ...

Or any other existing metaclass.

But, mypy treats ABCMeta and AbstractModel differently:

from abc import ABCMeta, abstractmethod
from typing import Protocol

class A:  # OK, has @abstractmethod
    @abstractmethod
    def f(self) -> None:
        pass

# Expected:
class B(A):  # E: Class a.B has abstract attributes "f"  # N: If it is meant to be abstract, add 'abc.ABCMeta' as an explicit metaclass
    pass

class C(A, metaclass=ABCMeta):  # OK, has ABCMeta as a metaclass
    pass

class CustomABC(ABCMeta):
    pass

# Unexpected:
class D(A, metaclass=CustomABC):  # E: Class a.D has abstract attributes "f"  # N: If it is meant to be abstract, add 'abc.ABCMeta' as an explicit metaclass
    pass

I think that needs to be fixed.

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

Successfully merging a pull request may close this issue.

2 participants