Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Closed
Description
Feature or enhancement
Proposal:
Up until Python 3.11, the output of the followingast.parse/unparse run
importastfromsysimportversion_infoasviprint(f"{vi.major}.{vi.minor}.{vi.micro}")print(ast.unparse(ast.parse("f\"{'.' * 5}\"")))
was
3.11.11f"{'.' * 5}"In Python 3.12,new f-string features were introduced, allowing for more general quote combinations. The output of the above script in Python 3.12 and 3.13 is
3.12.7f'{'.' * 5}'While this is legal Python 3.12/3.13, this representation needlessly restricts the usability of the generated code: It will not work on Python 3.11 and earlier.
I would thus like to suggest forast.unparse to return, if possible, the more compatible code; in this case
f"{'.' * 5}"which works across all currently supported Python versions.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response