-
-
Notifications
You must be signed in to change notification settings - Fork 32k
can not unparse code with ' in format_spec #112364
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
Comments
Will take a look this week |
I took a look at this issue and I think switching to a different set of quotes is too complex so the best way foward is that unparse scapes the quote. @isidentical @lysnikolaou WDYT? |
import ast
code1="""f"{something:'}" """
code2="""f'{something:\\'}' """
print(code1)
print(code2)
tree1=ast.parse(code1)
tree2=ast.parse(code2)
print("Trees equal: ", tree1 == tree2)
dump1 = ast.dump(tree1, indent=2)
dump2 = ast.dump(tree2, indent=2)
print("Dumps equal: ", dump1 == dump2)
print("Unparses equal: ", ast.unparse(tree1) == ast.unparse(tree2)) # IE both same bug. prints
Assuming that the tree difference is as unconsequential for compiles as it is for the dumps, the escape looks fine to me. ast.unparse(tree2) == astunparse( |
Looks like it is:
and
|
@pablogsal do you want to fix this issue? I could fix this bug if you want. That would be my first cpython Bugfix. |
Yes, let's fix it. Can you make a PR and CC me into it? Let's get your first CPython bug fix in 🚀 |
…n ast.unparse (pythonGH-115696) (cherry picked from commit 69ab930) Co-authored-by: Frank Hoffmann <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Bug description:
The following example shows that it is not possible to unparse a f-string with a ' in the format_spec, but such code can be generated when the f-string is double-quoted.
expected behaviour:
unparse
should use different quotes if quotes are part of the format_spec.This is only a problem in 3.12 and worked in 3.11
output (Python 3.12.0):
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: