Skip to content

Commit 221a7f3

Browse files
hauntsaninjaJukkaL
authored andcommitted
Fix PEP 585 type aliases in stubs (#11918)
Fixes #11859 Co-authored-by: hauntsaninja <>
1 parent b40c3d0 commit 221a7f3

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Diff for: mypy/semanal.py

+1
Original file line numberDiff line numberDiff line change
@@ -4089,6 +4089,7 @@ def analyze_type_application(self, expr: IndexExpr) -> None:
40894089
name = target.type.fullname
40904090
if (alias.no_args and # this avoids bogus errors for already reported aliases
40914091
name in get_nongen_builtins(self.options.python_version) and
4092+
not self.is_stub_file and
40924093
not alias.normalized):
40934094
self.fail(no_subscript_builtin_alias(name, propose_alt=False), expr)
40944095
# ...or directly.

Diff for: test-data/unit/check-generic-alias.test

+11
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,14 @@ class C(list[int]):
285285
pass
286286
d: type[str]
287287
[builtins fixtures/list.pyi]
288+
289+
290+
[case testTypeAliasWithBuiltinListAliasInStub]
291+
# flags: --python-version 3.6
292+
import m
293+
reveal_type(m.a()[0]) # N: Revealed type is "builtins.int*"
294+
295+
[file m.pyi]
296+
List = list
297+
a = List[int]
298+
[builtins fixtures/list.pyi]

0 commit comments

Comments
 (0)