Skip to content

string-processing: f-strings with quoted debug expressions #4493

@MichaReiser

Description

@MichaReiser

Describe the bug

The string-processing produces an invalid f-string when joining together two strings where both literals have a debug expression with quotes

f"{10 + len('bar')=}" f'{10 + len("bar")=}'
Cannot parse for target version Python 3.13: 2:30: f"{10 + len('bar')=}{10 + len(\"bar\")=}"

To Reproduce

Playground

Expected behavior

Black shouldn't join f-strings containing debug expressions with different quotes because changing the quotes would change the runtime behavior (the printed expressions use different quotes)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: preview styleIssues with the preview and unstable style. Add the name of the responsible feature in the title.F: stringsRelated to our handling of stringsT: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions