Skip to content

Check syntax errors in "# type: ignore[code]" comments #7460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Minor refactoring
  • Loading branch information
JukkaL committed Sep 4, 2019
commit 4c7c8bb9645fe11e0dd078efec85ab542de5e2f4
7 changes: 4 additions & 3 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def ast3_parse(source: Union[str, bytes], filename: str, mode: str,

TYPE_COMMENT_SYNTAX_ERROR = 'syntax error in type comment' # type: Final

INVALID_TYPE_IGNORE = 'Invalid "type: ignore" comment' # type: Final

TYPE_IGNORE_PATTERN = re.compile(r'[^#]*#\s*type:\s*ignore\s*\b(.*)')


Expand Down Expand Up @@ -215,8 +217,7 @@ def parse_type_comment(type_comment: str,
ignored = [] # Ignore everything
if ignored is None:
if errors is not None:
errors.report(line, column, 'Invalid "type: ignore" comment',
code=codes.SYNTAX)
errors.report(line, column, INVALID_TYPE_IGNORE, code=codes.SYNTAX)
else:
raise SyntaxError
else:
Expand Down Expand Up @@ -470,7 +471,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" comment', ti.lineno, -1)
self.fail(INVALID_TYPE_IGNORE, ti.lineno, -1)
body = self.fix_function_overloads(self.translate_stmt_list(mod.body, ismodule=True))
return MypyFile(body,
self.imports,
Expand Down
6 changes: 3 additions & 3 deletions mypy/fastparse2.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from mypy.errors import Errors
from mypy.fastparse import (
TypeConverter, parse_type_comment, bytes_to_human_readable_repr, parse_type_ignore_tag,
TYPE_IGNORE_PATTERN
TYPE_IGNORE_PATTERN, INVALID_TYPE_IGNORE
)
from mypy.options import Options
from mypy.reachability import mark_block_unreachable
Expand Down Expand Up @@ -348,7 +348,7 @@ def visit_Module(self, mod: ast27.Module) -> MypyFile:
if parsed is not None:
self.type_ignores[ti.lineno] = parsed
else:
self.fail('Invalid "type: ignore" comment', ti.lineno, -1)
self.fail(INVALID_TYPE_IGNORE, ti.lineno, -1)
body = self.fix_function_overloads(self.translate_stmt_list(mod.body))
return MypyFile(body,
self.imports,
Expand Down Expand Up @@ -563,7 +563,7 @@ def get_type(self,
else:
ignored = []
if ignored is None:
self.fail('Invalid "type: ignore" comment', converter.line, -1)
self.fail(INVALID_TYPE_IGNORE, converter.line, -1)
else:
self.type_ignores[converter.line] = ignored
return typ
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy