Skip to content

Commit fd2d684

Browse files
Treat ABCMeta subtypes as abstract metaclasses (#13562)
Closes #13561 Co-authored-by: Shantanu <[email protected]>
1 parent 0a8d425 commit fd2d684

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

mypy/semanal_classprop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def calculate_class_abstract_status(typ: TypeInfo, is_stub_file: bool, errors: E
9595
# implement some methods.
9696
typ.abstract_attributes = sorted(abstract)
9797
if is_stub_file:
98-
if typ.declared_metaclass and typ.declared_metaclass.type.fullname == "abc.ABCMeta":
98+
if typ.declared_metaclass and typ.declared_metaclass.type.has_base("abc.ABCMeta"):
9999
return
100100
if typ.is_protocol:
101101
return

test-data/unit/check-classes.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5497,6 +5497,13 @@ class E(Protocol): # OK, is a protocol
54975497
class F(E, Protocol): # OK, is a protocol
54985498
pass
54995499

5500+
# Custom metaclass subclassing `ABCMeta`, see #13561
5501+
class CustomMeta(ABCMeta):
5502+
pass
5503+
5504+
class G(A, metaclass=CustomMeta): # Ok, has CustomMeta as a metaclass
5505+
pass
5506+
55005507
[file b.py]
55015508
# All of these are OK because this is not a stub file.
55025509
from abc import ABCMeta, abstractmethod
@@ -5525,6 +5532,12 @@ class E(Protocol):
55255532
class F(E, Protocol):
55265533
pass
55275534

5535+
class CustomMeta(ABCMeta):
5536+
pass
5537+
5538+
class G(A, metaclass=CustomMeta):
5539+
pass
5540+
55285541
[case testClassMethodOverride]
55295542
from typing import Callable, Any
55305543

0 commit comments

Comments
 (0)