Skip to content

Edge case in FormatSpec::parse #23360

@ntBre

Description

@ntBre

I noticed while reviewing #21069 that a case like this:

f"{1:\x64}"

results in an Err from FormatSpec::parse despite being valid on Python 3.11:

Python 3.11.13 (main, Sep  2 2025, 14:20:25) [Clang 20.1.4 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> f"{1:\x64}"
'1'

and also 3.14:

Python 3.14.2 (main, Dec  9 2025, 19:03:28) [Clang 21.1.4 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> f"{1:\x64}"
'1'

(and I assume all other versions as well, #21069 was just about the behavior of backslashes in interpolations in 3.11 vs 3.12+).

This seems like quite a niche issue, and you can see that GitHub's syntax highlighting doesn't like it either, but I wanted to open a follow-up issue regardless.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions