Skip to content

Commit

Permalink
Fix whole-file ignoring. (#6853)
Browse files Browse the repository at this point in the history
Fixes #6852, and adds a regression test.
  • Loading branch information
brandtbucher authored and gvanrossum committed May 20, 2019
1 parent 56d4504 commit 728bbfd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion mypy/fastparse2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions test-data/unit/check-ignore.test
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ IGNORE
def f(): ...
IGNORE

[case testIgnoreWholeModule5]
# type: ignore
import MISSING

[case testDontIgnoreWholeModule1]
if True:
# type: ignore
Expand Down

0 comments on commit 728bbfd

Please sign in to comment.