Skip to content

Commit 58df567

Browse files
committed
Indexing a type also produces a GenericAlias
Mentioned by Jelle in python#17543 (comment)
1 parent 0a040dd commit 58df567

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

mypy/checkexpr.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4341,14 +4341,11 @@ def visit_index_with_type(
43414341
elif isinstance(left_type, FunctionLike) and left_type.is_type_obj():
43424342
if left_type.type_object().is_enum:
43434343
return self.visit_enum_index_expr(left_type.type_object(), e.index, e)
4344-
elif left_type.type_object().type_vars and self.chk.options.python_version >= (3, 9):
4345-
return self.named_type("types.GenericAlias")
4346-
elif (
4347-
left_type.type_object().fullname == "builtins.type"
4348-
and self.chk.options.python_version >= (3, 9)
4344+
elif self.chk.options.python_version >= (3, 9) and (
4345+
left_type.type_object().type_vars
4346+
or left_type.type_object().fullname == "builtins.type"
43494347
):
4350-
# builtins.type is special: it's not generic in stubs, but it supports indexing
4351-
return self.named_type("typing._SpecialForm")
4348+
return self.named_type("types.GenericAlias")
43524349

43534350
if isinstance(left_type, TypeVarType) and not self.has_member(
43544351
left_type.upper_bound, "__getitem__"

0 commit comments

Comments
 (0)