-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Closed
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtopic-parsertype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
Up until Python 3.11, the output of the following ast.parse
/unparse
run
import ast
from sys import version_info as vi
print(f"{vi.major}.{vi.minor}.{vi.micro}")
print(ast.unparse(ast.parse("f\"{'.' * 5}\"")))
was
3.11.11
f"{'.' * 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.7
f'{'.' * 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 for ast.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
Linked PRs
Metadata
Metadata
Assignees
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtopic-parsertype-featureA feature request or enhancementA feature request or enhancement