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

Self-documenting f-string in conversion specifier throws ValueError #121130

Closed
Labels
3.12only security fixes3.13bugs and security fixes3.14bugs and security fixestype-bugAn unexpected behavior, bug, or error
@JelleZijlstra

Description

@JelleZijlstra

Bug report

Bug description:

Since Python 3.12, the compiler throws a ValueError when compiling a string likef"{x:{y=}}":

$ ./python.exePython3.14.0a0 (heads/main:81a654a342,Jun282024,07:45:17) [Clang15.0.0 (clang-1500.3.9.4)]ondarwinType"help","copyright","credits"or"license"formoreinformation.>>>f"{x:{y=}}"ValueError:field'value'isrequiredforConstant

Note this is a compile-time error; you also see it if you callcompile() orast.parse(). I would not expect the compiler to ever throw ValueError.

On 3.11, this works as I'd expect:

$ pythonPython 3.11.9 (main, May  7 2024, 09:02:19) [Clang 15.0.0 (clang-1500.3.9.4)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> f"{x:{y=}}"Traceback (most recent call last):  File "<stdin>", line 1, in <module>NameError: name 'x' is not defined>>> import ast>>> ast.dump(ast.parse('f"{x:{y=}}"'))"Module(body=[Expr(value=JoinedStr(values=[FormattedValue(value=Name(id='x', ctx=Load()), conversion=-1, format_spec=JoinedStr(values=[Constant(value='y='), FormattedValue(value=Name(id='y', ctx=Load()), conversion=114)]))]))], type_ignores=[])"

I don't have a use case for this, but came across it while exploring f-string syntax.

cc@ericvsmith for f-strings and@pablogsal because this feels related to PEP 701

CPython versions tested on:

3.12, CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixes3.14bugs and security fixestype-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