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

Provide a more useful error when parsing fails during AST safety checks (#2218) #2218

Closed
wants to merge 1 commit into from

Conversation

hramezani
Copy link
Contributor

Fixes #2178

@ichard26 ichard26 self-requested a review May 10, 2021 15:28
try:
return ast27.parse(src)
except SyntaxError as e:
raise SyntaxError(error or str(e))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firstly, thanks for the PR!

If I'm not mistaken, this means that 2.7 errors are never passed onwards. To get to this try some other try above must fail, then error always has a value and the or short circuits. Indeed this only ever prints the error for Python 3.6, because it's the last to fail before 2.7. So this moves the problem from 2.7 to 3.6, but I'm pretty sure this is not quite the optimal solution.

The linked issue spoke of reparsing with the latest Python version available, and that idea had some agreement. That could be possible using sys.version_info and iffing the parser versions again.

felix-hilden pushed a commit to felix-hilden/black that referenced this pull request Jun 3, 2021
felix-hilden pushed a commit to felix-hilden/black that referenced this pull request Jun 3, 2021
felix-hilden pushed a commit to felix-hilden/black that referenced this pull request Jun 3, 2021
@felix-hilden
Copy link
Collaborator

Reading the issue once more, my previous review was a bit off the mark still. But I took your branch and improved on it in the referenced PR above. Many thanks for the initial work!

@ichard26
Copy link
Collaborator

Felix's PR (#2304) which is based off this work has been merged now so this will be closed. Thank you for the initial work @hramezani! Your ideas will continue to live in this codebase :)

@ichard26 ichard26 closed this Jul 13, 2021
@hramezani
Copy link
Contributor Author

Thanks @felix-hilden for taking care

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

Successfully merging this pull request may close these issues.

Provide a more useful error when parsing fails during AST safety checks
3 participants