-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-112364: correct unparsing of backslashes and quotes #115696
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
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
5290f7f
to
ced3764
Compare
@pablogsal I think this solves the issue. Did I miss anything? |
@@ -0,0 +1 @@ | |||
Fixed :func:`ast.unparse` to handle format_spec with ``"``, ``'`` or ``\\`` |
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.
Add "Patch by Frank Hoffmann" at the end 😉
Lib/test/test_unparse.py
Outdated
@@ -649,6 +649,21 @@ def test_multiquote_joined_string(self): | |||
self.check_ast_roundtrip("""f'''""\"''\\'{"\\n\\"'"}''' """) | |||
self.check_ast_roundtrip("""f'''""\"''\\'{""\"\\n\\"'''""\" '''\\n'''}''' """) | |||
|
|||
def test_backslash_in_format_spec(self): | |||
self.check_ast_roundtrip("""f"{x:\\}" """) |
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.
Can you add some tests with an uneven number of \
?
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.
Something like this should be valid:
>>> class A:
... def __format__(self, *args):
... print(args)
... return "foo"
...
>>> f"{ A():\\\ }"
('\\\\ ',)
'foo'
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 confused me and I checked it.
>>> len("""\\""")
1
This example already has 1,2,3 and 4 backslashes. But I added a space at the end like in your example.
ced3764
to
c5468f4
Compare
LGTM! Great job and congratulations on your first CPython bugfix! 🎉 Hopefully the first of many 😉 |
Thanks @15r10nk for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
Sorry, @15r10nk and @pablogsal, I could not cleanly backport this to
|
@15r10nk Can you follow these instructions to do the 3.12 backport? |
Yes, I will port it back in the evening. |
GH-115782 is a backport of this pull request to the 3.12 branch. |
…n ast.unparse (pythonGH-115696) (cherry picked from commit 69ab930) Co-authored-by: Frank Hoffmann <[email protected]>
This pull-request fixes also two other things which are related to the original issue:
"
can cause the same problem than'
\
backslashes where not escaped which converted\\
into\
and not\\
.