Skip to content

Commit

Permalink
Make invalid type ignore comments non-blocking (#13506)
Browse files Browse the repository at this point in the history
Blocking errors are a bad user experience and there's no reason for this
one to be one / there is another code path for invalid type ignores that
is non-blocking.

Fixes half of #12299. The half it doesn't fix is that ideally users
shouldn't be getting these warnings from third party libraries.
Also see #12162 (comment)
But that's for another PR
  • Loading branch information
hauntsaninja authored Aug 25, 2022
1 parent 3d015af commit d9750c6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ def visit_Module(self, mod: ast3.Module) -> MypyFile:
if parsed is not None:
self.type_ignores[ti.lineno] = parsed
else:
self.fail(INVALID_TYPE_IGNORE, ti.lineno, -1)
self.fail(INVALID_TYPE_IGNORE, ti.lineno, -1, blocker=False)
body = self.fix_function_overloads(self.translate_stmt_list(mod.body, ismodule=True))
return MypyFile(body, self.imports, False, self.type_ignores)

Expand Down
6 changes: 5 additions & 1 deletion test-data/unit/check-errorcodes.test
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ import nostub # type: ignore[import]
from defusedxml import xyz # type: ignore[import]

[case testErrorCodeBadIgnore]
import nostub # type: ignore xyz # E: Invalid "type: ignore" comment [syntax]
import nostub # type: ignore xyz # E: Invalid "type: ignore" comment [syntax] \
# E: Cannot find implementation or library stub for module named "nostub" [import] \
# N: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
import nostub # type: ignore[ # E: Invalid "type: ignore" comment [syntax]
import nostub # type: ignore[foo # E: Invalid "type: ignore" comment [syntax]
import nostub # type: ignore[foo, # E: Invalid "type: ignore" comment [syntax]
Expand All @@ -207,6 +209,8 @@ def f(x, # type: int # type: ignore[
pass
[out]
main:2: error: Invalid "type: ignore" comment [syntax]
main:2: error: Cannot find implementation or library stub for module named "nostub" [import]
main:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
main:3: error: Invalid "type: ignore" comment [syntax]
main:4: error: Invalid "type: ignore" comment [syntax]
main:5: error: Invalid "type: ignore" comment [syntax]
Expand Down

0 comments on commit d9750c6

Please sign in to comment.