Skip to content

Commit 0ca2ae3

Browse files
committed
refactor(mypy): accept any TypeType as a deferred member base; avoid regression for inferred class attrs
1 parent 1bd26bd commit 0ca2ae3

2 files changed

Lines changed: 3 additions & 6 deletions

File tree

‎mypy/checker.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,8 +2855,9 @@ def check_deferred_member_bases(self, defn: ClassDef) -> None:
28552855
or isinstance(typ, TypeType)
28562856
and isinstance(typ.item, AnyType)
28572857
)
2858-
if is_any_base:
2859-
if self.options.disallow_subclassing_any:
2858+
is_type_type = isinstance(typ, TypeType)
2859+
if is_any_base or is_type_type:
2860+
if is_any_base and self.options.disallow_subclassing_any:
28602861
self.fail(
28612862
f'Class cannot subclass "{base_expr.name}" (has type "Any")', base_expr
28622863
)

‎mypy/semanal.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,10 +2667,6 @@ def analyze_base_classes(
26672667
isinstance(member_type, Instance)
26682668
and member_type.type.fullname == "builtins.type"
26692669
)
2670-
or (
2671-
isinstance(member_type, TypeType)
2672-
and isinstance(member_type.item, AnyType)
2673-
)
26742670
):
26752671
# The attribute is a type object. Treat it like a variable
26762672
# annotated with ``type``, which is accepted as a base class.

0 commit comments

Comments
 (0)