Skip to content

Commit

Permalink
Treat ABCMeta subtypes as abstract metaclasses (#13562)
Browse files Browse the repository at this point in the history
Closes #13561

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
  • Loading branch information
sobolevn and hauntsaninja authored Sep 3, 2022
1 parent 0a8d425 commit fd2d684
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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

0 comments on commit fd2d684

Please sign in to comment.