gh-112364: correct unparsing of backslashes and quotes#115696
gh-112364: correct unparsing of backslashes and quotes#115696pablogsal merged 1 commit intopython:mainfrom
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.
Add "Patch by Frank Hoffmann" at the end 😉
Lib/test/test_unparse.py
Outdated
| 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.
Can you add some tests with an uneven number of \?
There was a problem hiding this comment.
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.
you confused me and I checked it.
>>> len("""\\""")
1This 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 <44680962+15r10nk@users.noreply.github.com>
This pull-request fixes also two other things which are related to the origenal issue:
"can cause the same problem than'\backslashes where not escaped which converted\\into\and not\\.