Skip to content

Commit

Permalink
Fix PEP 585 type aliases in stubs (#11918)
Browse files Browse the repository at this point in the history
Fixes #11859

Co-authored-by: hauntsaninja <>
  • Loading branch information
hauntsaninja authored and JukkaL committed Jan 6, 2022
1 parent b40c3d0 commit 221a7f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4089,6 +4089,7 @@ def analyze_type_application(self, expr: IndexExpr) -> None:
name = target.type.fullname
if (alias.no_args and # this avoids bogus errors for already reported aliases
name in get_nongen_builtins(self.options.python_version) and
not self.is_stub_file and
not alias.normalized):
self.fail(no_subscript_builtin_alias(name, propose_alt=False), expr)
# ...or directly.
Expand Down
11 changes: 11 additions & 0 deletions test-data/unit/check-generic-alias.test
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,14 @@ class C(list[int]):
pass
d: type[str]
[builtins fixtures/list.pyi]


[case testTypeAliasWithBuiltinListAliasInStub]
# flags: --python-version 3.6
import m
reveal_type(m.a()[0]) # N: Revealed type is "builtins.int*"

[file m.pyi]
List = list
a = List[int]
[builtins fixtures/list.pyi]

0 comments on commit 221a7f3

Please sign in to comment.