Skip to content

Formatter does not apply nested-string-quote-style alternation inside format-spec interpolations #28218

Closed

Description

@ikeyan

When the formatter normalizes an f-string's outer quotes to the configured quote-style, nested-string-quote-style = "alternating" (the default) is applied to string literals in normal interpolations, but not to string literals in interpolations inside a format spec.

$ cat mini.py
a = f'x {d["k"]} y'
b = f'x {v:,.{d["n"]}f} y'
$ ruff format --isolated mini.py
1 file reformatted
$ cat mini.py
a = f"x {d['k']} y"
b = f"x {v:,.{d["n"]}f} y"

a: inner quotes alternated to '. b: the interpolation inside the format spec keeps ", reusing the outer quote.

When targeting Python < 3.12 (e.g. requires-python = ">=3.11"), the output is then also a syntax error (PEP 701 quote reuse), rejected by ruff check itself:

invalid-syntax: Cannot reuse outer quote character in f-strings on Python 3.11 (syntax was added in Python 3.12)

ruff 0.16.5.

Activity

  1. changed the title [-]Formatter reuses outer quote in f-string format-spec interpolations, emitting pre-3.12 invalid syntax with target-version py311[/-] [+]Formatter does not apply nested-string-quote-style alternation inside format-spec interpolations[/+] on Sep 1, 2026
  2. ntBre commented on Sep 1, 2026

    @ntBre
    Contributor

    Thanks for the report! It looks like I introduced this in #20930.

  3. added
    bug
    formatter
    on Sep 1, 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

    bugformatter

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions