Skip to content

Commit 2ff3fae

Browse files
committed
Handle type[...] same as typing.Type[...] in classmethod 1st arg
1 parent c0af000 commit 2ff3fae

File tree

2 files changed

+1092
-1
lines changed

2 files changed

+1092
-1
lines changed

mypy/semanal.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,21 @@ def is_expected_self_type(self, typ: Type, is_classmethod: bool) -> bool:
10081008
return self.is_expected_self_type(typ.item, is_classmethod=False)
10091009
if isinstance(typ, UnboundType):
10101010
sym = self.lookup_qualified(typ.name, typ, suppress_errors=True)
1011-
if sym is not None and sym.fullname == "typing.Type" and typ.args:
1011+
if (
1012+
sym is not None
1013+
and typ.args
1014+
and (
1015+
sym.fullname == "typing.Type"
1016+
or (
1017+
sym.fullname == "builtins.type"
1018+
and (
1019+
self.is_stub_file
1020+
or self.is_future_flag_set("annotations")
1021+
or self.options.python_version >= (3, 9)
1022+
)
1023+
)
1024+
)
1025+
):
10121026
return self.is_expected_self_type(typ.args[0], is_classmethod=False)
10131027
return False
10141028
if isinstance(typ, TypeVarType):

0 commit comments

Comments
 (0)