-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Ouput bad comment during syntax error #6779
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
Conversation
You need to update existing tests. They are currently failing. |
This is a good idea, but I'd like to see some tests (and the existing tests that are failing fixed). You also ought to add the same thing to |
mypy/fastparse.py
Outdated
@@ -192,7 +192,8 @@ def parse_type_comment(type_comment: str, | |||
typ = ast3_parse(type_comment, '<type_comment>', 'eval') | |||
except SyntaxError as e: | |||
if errors is not None: | |||
errors.report(line, e.offset, TYPE_COMMENT_SYNTAX_ERROR, blocker=True) | |||
err_msg = "{} '{}'".format(TYPE_COMMENT_SYNTAX_ERROR, type_comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would strip everything in the type_comment
after #
, so that only the interesting part is shown.
test-data/unit/parse-errors.test
Outdated
file:2: error: syntax error in type comment | ||
file:2: error: syntax error in type comment '*' | ||
|
||
[case testInvalidTypeComment5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have missing closing ]
here in in couple tests below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now! I will merge when tests pass in CI.
mypy/fastparse2.py
Outdated
@@ -337,6 +337,7 @@ def visit_FunctionDef(self, n: ast27.FunctionDef) -> Statement: | |||
return_type = None | |||
elif type_comment is not None and len(type_comment) > 0: | |||
try: | |||
print(type_comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stray debugging print left.
Your last commit will likely cause many failures in CI (because at least some existing tests need to be updated). It is much easier to run tests locally first, since now the line in CI is really long, your PR might wait for an hour there. |
I wanted to get the function annotations in the same PR so I'm okay with it taking a bit. Thanks for all the help @ilevkivskyi. |
fixes #4103