Skip to content

ABCMeta and its subclasses are treated differently #13561

Description

@sobolevn

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:

fromdjang.db.modelsimportModelBasefromabcimportABCMetaclassAbstractModel(ABCMeta, ModelBase): ...

Or any other existing metaclass.

But, mypy treats ABCMeta and AbstractModel differently:

fromabcimportABCMeta, abstractmethodfromtypingimportProtocolclassA: # OK, has @abstractmethod@abstractmethoddeff(self) ->None:
pass# Expected:classB(A): # E: Class a.B has abstract attributes "f" # N: If it is meant to be abstract, add 'abc.ABCMeta' as an explicit metaclasspassclassC(A, metaclass=ABCMeta): # OK, has ABCMeta as a metaclasspassclassCustomABC(ABCMeta):
pass# Unexpected:classD(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 metaclasspass

I think that needs to be fixed.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions