Skip to content
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

Treat ABCMeta subtypes as abstract metaclasses #13562

Merged
merged 2 commits into from
Sep 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/semanal_classprop.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def calculate_class_abstract_status(typ: TypeInfo, is_stub_file: bool, errors: E
# implement some methods.
typ.abstract_attributes = sorted(abstract)
if is_stub_file:
if typ.declared_metaclass and typ.declared_metaclass.type.fullname == "abc.ABCMeta":
if typ.declared_metaclass and typ.declared_metaclass.type.has_base("abc.ABCMeta"):
return
if typ.is_protocol:
return
Expand Down
13 changes: 13 additions & 0 deletions test-data/unit/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -5497,6 +5497,13 @@ class E(Protocol): # OK, is a protocol
class F(E, Protocol): # OK, is a protocol
pass

# Custom metaclass subclassing `ABCMeta`, see #13561
class CustomMeta(ABCMeta):
pass

class G(A, metaclass=CustomMeta): # Ok, has CustomMeta as a metaclass
pass

[file b.py]
# All of these are OK because this is not a stub file.
from abc import ABCMeta, abstractmethod
Expand Down Expand Up @@ -5525,6 +5532,12 @@ class E(Protocol):
class F(E, Protocol):
pass

class CustomMeta(ABCMeta):
pass

class G(A, metaclass=CustomMeta):
pass

[case testClassMethodOverride]
from typing import Callable, Any

Expand Down