From 221a7f34cbfdc0dafe7f84042f2a707cbfdbf60f Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Thu, 6 Jan 2022 01:44:10 -0800 Subject: [PATCH] Fix PEP 585 type aliases in stubs (#11918) Fixes #11859 Co-authored-by: hauntsaninja <> --- mypy/semanal.py | 1 + test-data/unit/check-generic-alias.test | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/mypy/semanal.py b/mypy/semanal.py index a948b5c8834d..01f39756ba11 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -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. diff --git a/test-data/unit/check-generic-alias.test b/test-data/unit/check-generic-alias.test index bfef0f5c5086..0f8be72c556f 100644 --- a/test-data/unit/check-generic-alias.test +++ b/test-data/unit/check-generic-alias.test @@ -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]