Skip to content

Commit 728bbfd

Browse files
brandtbuchergvanrossum
authored andcommitted
Fix whole-file ignoring. (#6853)
Fixes #6852, and adds a regression test.
1 parent 56d4504 commit 728bbfd

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

mypy/fastparse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from mypy import message_registry
3939
from mypy.errors import Errors
4040
from mypy.options import Options
41+
from mypy.reachability import mark_block_unreachable
4142

4243
try:
4344
# pull this into a final variable to make mypyc be quiet about the
@@ -311,7 +312,7 @@ def translate_stmt_list(self,
311312
and min(self.type_ignores) < self.get_lineno(stmts[0])):
312313
self.errors.used_ignored_lines[self.errors.file].add(min(self.type_ignores))
313314
block = Block(self.fix_function_overloads(self.translate_stmt_list(stmts)))
314-
block.is_unreachable = True
315+
mark_block_unreachable(block)
315316
return [block]
316317

317318
res = [] # type: List[Statement]

mypy/fastparse2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from mypy.errors import Errors
4848
from mypy.fastparse import TypeConverter, parse_type_comment, bytes_to_human_readable_repr
4949
from mypy.options import Options
50+
from mypy.reachability import mark_block_unreachable
5051

5152
try:
5253
from typed_ast import ast27
@@ -209,7 +210,7 @@ def translate_stmt_list(self,
209210
and min(self.type_ignores) < self.get_lineno(stmts[0])):
210211
self.errors.used_ignored_lines[self.errors.file].add(min(self.type_ignores))
211212
block = Block(self.fix_function_overloads(self.translate_stmt_list(stmts)))
212-
block.is_unreachable = True
213+
mark_block_unreachable(block)
213214
return [block]
214215

215216
res = [] # type: List[Statement]

test-data/unit/check-ignore.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ IGNORE
242242
def f(): ...
243243
IGNORE
244244

245+
[case testIgnoreWholeModule5]
246+
# type: ignore
247+
import MISSING
248+
245249
[case testDontIgnoreWholeModule1]
246250
if True:
247251
# type: ignore

0 commit comments

Comments
 (0)