From 728bbfdc21229114ee862bc4593e7c274b323c4e Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Mon, 20 May 2019 09:32:17 -0700 Subject: [PATCH] Fix whole-file ignoring. (#6853) Fixes #6852, and adds a regression test. --- mypy/fastparse.py | 3 ++- mypy/fastparse2.py | 3 ++- test-data/unit/check-ignore.test | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mypy/fastparse.py b/mypy/fastparse.py index c6fb9c957a6af..f0181b295c1f5 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -38,6 +38,7 @@ from mypy import message_registry from mypy.errors import Errors from mypy.options import Options +from mypy.reachability import mark_block_unreachable try: # pull this into a final variable to make mypyc be quiet about the @@ -311,7 +312,7 @@ def translate_stmt_list(self, and min(self.type_ignores) < self.get_lineno(stmts[0])): self.errors.used_ignored_lines[self.errors.file].add(min(self.type_ignores)) block = Block(self.fix_function_overloads(self.translate_stmt_list(stmts))) - block.is_unreachable = True + mark_block_unreachable(block) return [block] res = [] # type: List[Statement] diff --git a/mypy/fastparse2.py b/mypy/fastparse2.py index a54a40a95005c..6d9c4ca1cd203 100644 --- a/mypy/fastparse2.py +++ b/mypy/fastparse2.py @@ -47,6 +47,7 @@ from mypy.errors import Errors from mypy.fastparse import TypeConverter, parse_type_comment, bytes_to_human_readable_repr from mypy.options import Options +from mypy.reachability import mark_block_unreachable try: from typed_ast import ast27 @@ -209,7 +210,7 @@ def translate_stmt_list(self, and min(self.type_ignores) < self.get_lineno(stmts[0])): self.errors.used_ignored_lines[self.errors.file].add(min(self.type_ignores)) block = Block(self.fix_function_overloads(self.translate_stmt_list(stmts))) - block.is_unreachable = True + mark_block_unreachable(block) return [block] res = [] # type: List[Statement] diff --git a/test-data/unit/check-ignore.test b/test-data/unit/check-ignore.test index 3992819a46486..3d6411031c71e 100644 --- a/test-data/unit/check-ignore.test +++ b/test-data/unit/check-ignore.test @@ -242,6 +242,10 @@ IGNORE def f(): ... IGNORE +[case testIgnoreWholeModule5] +# type: ignore +import MISSING + [case testDontIgnoreWholeModule1] if True: # type: ignore