From 9f2c5b40041527cff41da8c1d91bc62097253b10 Mon Sep 17 00:00:00 2001 From: cdce8p <30130371+cdce8p@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:25:22 +0200 Subject: [PATCH] Fix for pep585 with __future__ import --- mypy/semanal.py | 2 +- test-data/unit/check-future.test | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/mypy/semanal.py b/mypy/semanal.py index 2ea444bf4ab26..19fa9c633b0dd 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -3792,7 +3792,7 @@ def analyze_type_application(self, expr: IndexExpr) -> None: # ...or directly. else: n = self.lookup_type_node(base) - if n and n.fullname in nongen_builtins: + if n and n.fullname in nongen_builtins and not self.is_future_flag_set("annotations"): self.fail(no_subscript_builtin_alias(n.fullname, propose_alt=False), expr) def analyze_type_application_args(self, expr: IndexExpr) -> Optional[List[Type]]: diff --git a/test-data/unit/check-future.test b/test-data/unit/check-future.test index 9ccf4eaa3dd25..28947d10ee8b1 100644 --- a/test-data/unit/check-future.test +++ b/test-data/unit/check-future.test @@ -20,5 +20,14 @@ t1: type[int] t2: list[int] t3: dict[int, int] t4: tuple[int, str, int] +t5 = list[int] [builtins fixtures/dict.pyi] + +[case testFutureAnnotationsMissing] +# flags: --python-version 3.7 + +t1: list[int] # E: "list" is not subscriptable, use "typing.List" instead +t2 = list[int] # E: "list" is not subscriptable + +[builtins fixtures/list.pyi]