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

t-strings: AST unparsing does not reproduce original formatting #133581

Closed
Labels
3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-parsertype-bugAn unexpected behavior, bug, or error
@JelleZijlstra

Description

@JelleZijlstra

Bug report

Bug description:

The AST unparsing ofInterpolation objects does not reproduce formatting within interpolations.

This is true both forast.unparse in Python:

>>> ast.unparse(ast.parse('t"{a   + b}"'))"t'{a + b}'"

And for the C unparse that is used byfrom __future__ import annotations:

>>> ns = {}>>> exec("""... from __future__ import annotations... def f(x: t"{a    + b}"): ...... """, ns)>>> ns["f"].__annotations__{'x': "t'{a + b}'"}

In general, we can't recover the original source exactly, but in this case we do have the original source available:

>>> ast.parse('t"{a   + b}"').body[0].value.values[0].str'a   + b'

Let's use it.

CPython versions tested on:

3.14

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-parsertype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp