Uh oh!
There was an error while loading. Please reload this page.
gh-108469: Update ast.unparse for unescaped quote support from PEP701 [3.12] - #108553
Conversation
sunmy2019
commented
Sep 2, 2023
Sorry that I have taken over. |
Uh oh!
There was an error while loading. Please reload this page.
tonybaloney
commented
Sep 2, 2023
You're welcome. I spent hours debugging these private methods and can't figure out which ones need removing or changing |
sunmy2019
commented
Sep 3, 2023
Oh, I've found some corner case that previous logic did not handle. Give me some time for a more thorough rewrite. |
sunmy2019
commented
Sep 3, 2023
I discovered it was a bug in the original implementation. Opened #108843. |
sunmy2019
commented
Sep 3, 2023
Fixed on this branch. |
| def visit_FormattedValue(self, node): | ||
| def unparse_inner(inner): | ||
| unparser = type(self)(_avoid_backslashes=True) | ||
| unparser = type(self)(_avoid_backslashes=False) |
There was a problem hiding this comment.
Do we still need this mode or can we drop avoid_backslashes all together?
| for c in value: | ||
| if c == "\\" or not c.isprintable(): | ||
| res.append(c.encode("unicode_escape").decode("ascii")) | ||
| continue | ||
| if c == quote: | ||
| if consecutive_quotes == len(quote_type) - 1: | ||
| # escape when we see a full `quote_type` | ||
| res.append("\\") | ||
| consecutive_quotes = 0 | ||
| else: | ||
| consecutive_quotes += 1 | ||
| else: | ||
| consecutive_quotes = 0 | ||
| res.append(c) |
There was a problem hiding this comment.
This logic probably belongs somewhere else, something similiar to what we had with the existing f-string unparsing implementation:
isidentical
commented
Sep 3, 2023
@sunmy2019 if we are interested in quickly shipping a fix for it, I'd avoid changing anything cosmetic and simply dropping the existing |
sunmy2019
commented
Sep 3, 2023
isidentical
commented
Sep 4, 2023
I think separting the fix for that from the actual PEP 701 support makes sense, and also reduces the possible complexity of changes this PR brings in. Let's first do the cleanup and the support for PEP 701 and we can do the fix later since this seems like the more serious problem. |
pablogsal
commented
Sep 4, 2023
Let's try to land this today or tomorrow. I added @Yhg1s to the PR so he is aware of it. |
sunmy2019
commented
Sep 5, 2023
I got it reverted. |
@sunmy2019 can you make a PR for the fix changes and ping me, @isidentical and @Yhg1s ? |
miss-islington
commented
Sep 5, 2023
Thanks @tonybaloney for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
…PEP701 [3.12] (pythonGH-108553) (cherry picked from commit 2c4c26c) Co-authored-by: Anthony Shaw <anthony.p.shaw@gmail.com> Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
bedevere-bot
commented
Sep 5, 2023
GH-108960 is a backport of this pull request to the 3.12 branch. |
sunmy2019
commented
Sep 6, 2023
Working on it. |
As of python#108553, the `_avoid_backslashes` code path is dead `scape_newlines` was introduced in python#110271. Happy to drop the typo fix if we don't want it
As of python#108553, the `_avoid_backslashes` code path is dead `scape_newlines` was introduced in python#110271. Happy to drop the typo fix if we don't want it
As of python#108553, the `_avoid_backslashes` code path is dead `scape_newlines` was introduced in python#110271. Happy to drop the typo fix if we don't want it
As of python#108553, the `_avoid_backslashes` code path is dead `scape_newlines` was introduced in python#110271. Happy to drop the typo fix if we don't want it
Uh oh!
There was an error while loading. Please reload this page.