From 6f07af0b2396bc1b9bb67c4d306adaa51fbbc599 Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Thu, 16 May 2019 17:10:35 -0700 Subject: [PATCH] Fix whole-file ignoring. --- 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 ec0556d598fc..bd5937d7b088 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 @@ -309,7 +310,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 0cea7706dacb..d2c688c527e7 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 @@ -207,7 +208,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 3992819a4648..3d6411031c71 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