-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
bpo-28002: Roundtrip f-strings with ast.unparse better #19612
Conversation
Some notes:
cc @isidentical |
811343d
to
66fee8a
Compare
The test failure in test_concurrent_futures on Windows x86 seems unrelated to this PR |
One issue with the PR as it stands is the perhaps undesirable unparsing of the following, probably reasonably common f-string:
For this to pass a src roundtrip, we'd need to process the buffer a little more intelligently when |
@hauntsaninja would you rebase and (if you liked it) apply the suggestions. So we can move forward, and try to improve it. I have a script that I'll plan to test this PR against top PyPI packages, so we might find more problems / or verify that it works well at the end. |
By attempting to avoid backslashes in f-string expressions. We also now proactively raise errors for some backslashes we can't avoid while unparsing FormattedValues
Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
FYI, this patch fails on roundtripping this file https://github.com/numpy/numpy/blob/master/tools/refguide_check.py |
What about not including the |
Thanks, updated to include your two comments! I think including Let me see if I can come up with a fix over the weekend, otherwise we can go ahead and make the |
A gentle ping @hauntsaninja |
The previous cosmetic fix means we use triple quotes less often, so this is less likely to occur in practice, but should be fixed anyway.
Thanks for the reminder! Made changes that should result in better cosmetic unparsing of cases like |
@isidentical Thanks for taking another look! I made the changes as suggested, except for the ones I replied to |
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.
@pablogsal would you mind checking out this?
Thanks for the continuous work @hauntsaninja! If you have time, please try the latest version on the most downloaded PyPI packages set, if not please let me know (so I can test it by myself). |
Also, you should be able to collapse my reviews (mark them as resolved) so that it won't distract people when reading the history. |
The CI failure here looks like a flake. I re-ran AST roundtripping over 4k packages and everything was clear (apart from some pre-existing RecursionErrors) |
A gentle ping @ericvsmith. Do you plan to take a look? |
I'd love for this to make 3.9.1, if possible! :-) |
closing and re-opening for the CI |
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.
Sorry for the delay. This looks reasonable enough to me, but someone who's more familiar with the AST and/or unparsing should take a look. Maybe @ambv?
re-triggering the CI (some irrelevant macos failure) |
@isidentical: Please replace |
Thanks @hauntsaninja for the PR, and @isidentical for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9. |
By attempting to avoid backslashes in f-string expressions. We also now proactively raise errors for some backslashes we can't avoid while unparsing FormattedValues Co-authored-by: hauntsaninja <> Co-authored-by: Shantanu <hauntsaninja@users.noreply.github.com> Co-authored-by: Batuhan Taskaya <isidentical@gmail.com> (cherry picked from commit a993e90) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
GH-23430 is a backport of this pull request to the 3.9 branch. |
…-23430) By attempting to avoid backslashes in f-string expressions. We also now proactively raise errors for some backslashes we can't avoid while unparsing FormattedValues Co-authored-by: hauntsaninja <> Co-authored-by: Shantanu <hauntsaninja@users.noreply.github.com> Co-authored-by: Batuhan Taskaya <isidentical@gmail.com> (cherry picked from commit a993e90) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Thank you so much for your continuous efforts on this issue @hauntsaninja. |
Thank you for making this PR happen! :-) |
By attempting to avoid backslashes in f-string expressions. We also now proactively raise errors for some backslashes we can't avoid while unparsing FormattedValues Co-authored-by: hauntsaninja <> Co-authored-by: Shantanu <hauntsaninja@users.noreply.github.com> Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
By attempting to avoid backslashes in f-string expressions.
We also now proactively raise errors for some backslashes we can't
avoid while unparsing FormattedValues
https://bugs.python.org/issue28002
Automerge-Triggered-By: GH:isidentical