Skip to content
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

When there's a syntax error, print the comment used #4103

Closed
Wilfred opened this issue Oct 12, 2017 · 3 comments · Fixed by #6779
Closed

When there's a syntax error, print the comment used #4103

Wilfred opened this issue Oct 12, 2017 · 3 comments · Fixed by #6779

Comments

@Wilfred
Copy link

Wilfred commented Oct 12, 2017

Given the Python code:

def big_function(
        x1, # type: Optional[int]
        x2, # type: Optional[int]
        x3, # type: Optional[int]
        x4, # type: Optional[int]
        x5, # type: Optional[int]]
        x6, # type: Optional[int]
        x7, # type: Optional[int]
):
    # type: (...) -> int
    return 123

Sometimes it's difficult to spot which comment has a syntax error. It would be nicer if mypy could print the comment it's looking at, to make it more obvious.

$ mypy --py2 bar.py
bar.py:1: error: syntax error in type comment
@JelleZijlstra
Copy link
Member

I agree, but I think this should be reported upstream to https://github.com/python/typed_ast.

@Wilfred
Copy link
Author

Wilfred commented Oct 12, 2017

It looks to me like the comment parsing happens in mypy: https://github.com/python/mypy/blob/master/mypy/fastparse2.py#L310-L312 . Presumably n.type_comment has the comment we're interested in?

@ilevkivskyi
Copy link
Member

Yes, I think it is possible for Python 2 to do this in mypy without changes to typed_ast. On the contrary Python 3 type annotations are parsed by Python parser and should be syntactically correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants