Skip to content

string_processing: Extra parentheses added even when string isn't split #3466

@wookie184

Description

@wookie184

Describe the bug
With preview style, a long f-string where the only spaces are in the expression bit has parentheses added even though it isn't split over lines. For example:

f(
    f'longstringwithnospacesinthestringbitbutwithspacesintheformattyfstringbithere{ 1 }',
)

becomes

f(
    (
        f"longstringwithnospacesinthestringbitbutwithspacesintheformattyfstringbithere{ 1 }"
    ),
)

I would instead expect it not to have changed. See on black playground

I noticed it also seems to occur with normal strings where the split is very near the start or end

f(
    "l ongstringwithnospacesinthestringbitbutwithspacesintheformattyfstringbitherelollol",
)

becomes

f(
    (
        "l ongstringwithnospacesinthestringbitbutwithspacesintheformattyfstringbitherelollol"
    ),
)

See on black playground
Version
Black 23.1a1, with --preview

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: parenthesesToo many parentheses, not enough parentheses, and so on.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