Skip to content

Commit fcf949f

Browse files
author
hauntsaninja
committed
Fix PEP 585 type aliases in stubs
Fixes python#11859
1 parent 37886c7 commit fcf949f

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
@@ -4085,6 +4085,7 @@ def analyze_type_application(self, expr: IndexExpr) -> None:
40854085
name = target.type.fullname
40864086
if (alias.no_args and # this avoids bogus errors for already reported aliases
40874087
name in get_nongen_builtins(self.options.python_version) and
4088+
not self.is_stub_file and
40884089
not alias.normalized):
40894090
self.fail(no_subscript_builtin_alias(name, propose_alt=False), expr)
40904091
# ...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)