Skip to content

Commit e0a89b7

Browse files
authored
Fix PEP 585 type aliases in stubs (#11918)
Fixes #11859 Co-authored-by: hauntsaninja <>
1 parent ce42116 commit e0a89b7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

mypy/semanal.py

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

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)