Skip to content

Commit

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

Co-authored-by: hauntsaninja <>
  • Loading branch information
hauntsaninja authored and tushar-deepsource committed Jan 20, 2022
1 parent e13b9af commit dc87dfa
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 @@ -4091,6 +4091,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 dc87dfa

Please sign in to comment.