Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ast.unparse is needlessly "hip" for f-string quotes in Python 3.12+ #127975

Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytopic-parsertype-featureA feature request or enhancement
@nschloe

Description

@nschloe

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

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-parsertype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp