Skip to content

ast.unparse can emit invalid syntax for literal braces in format specifiers #162622

Description

@tonghuaroot

Bug report

using a literal opening brace as the fill character works in the original f string. ast.unparse writes the brace without escaping it, so parsing the generated source raises a syntax error.

import ast

source = r'f"{7:\x7b>3}"'
print(eval(source))
print(eval(ast.unparse(ast.parse(source, mode="eval"))))

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added a commit that references this issue on Nov 25, 2026
  2. added
    stdlib
    type-bug
    on Nov 25, 2026
  3. added a commit that references this issue on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibtype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions