8000 Indexing a type also produces a GenericAlias by hauntsaninja · Pull Request #17546 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Indexing a type also produces a GenericAlias #17546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Indexing a type also produces a GenericAlias
Mentioned by Jelle in #17543 (comment)
  • Loading branch information
hauntsaninja committed Jul 20, 2024
commit 58df567269b2b628af0ac1ceed2ebf466b505b48
11 changes: 4 additions & 7 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4341,14 +4341,11 @@ def visit_index_with_type(
elif isinstance(left_type, FunctionLike) and left_type.is_type_obj():
if left_type.type_object().is_enum:
return self.visit_enum_index_expr(left_type.type_object(), e.index, e)
elif left_type.type_object().type_vars and self.chk.options.python_version >= (3, 9):
return self.named_type("types.GenericAlias")
elif (
left_type.type_object().fullname == "builtins.type"
and self.chk.options.python_version >= (3, 9)
elif self.chk.options.python_version >= (3, 9) and (
left_type.type_object().type_vars
or left_type.type_object().fullname == "builtins.type"
):
# builtins.type is special: it's not generic in stubs, but it supports indexing
return self.named_type("typing._SpecialForm")
return self.named_type("types.GenericAlias")

if isinstance(left_type, TypeVarType) and not self.has_member(
left_type.upper_bound, "__getitem__"
Expand Down
Loading
0