Skip to content

Consider keeping the parens of implicitly concatenated strings when it's a argument of a function call #3260

@yilei

Description

@yilei

Describe the style change

Original code:

function_call(
    (
        " lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor"
        " incididunt ut labore et dolore magna aliqua Ut enim ad minim"
    ),
    " veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo",
)

Examples in the current Black preview style

black --preview removes the parens since they are "not necessary":

function_call(
    " lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor"
    " incididunt ut labore et dolore magna aliqua Ut enim ad minim",
    " veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo",
)

Desired style

Keep the parens:

function_call(
    (
        " lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor"
        " incididunt ut labore et dolore magna aliqua Ut enim ad minim"
    ),
    " veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo",
)

Additional context

Parens in this case can increase readability, Black can choose to NOT universally add parens for them (see #3162 (comment)). However, if the code explicitly adds parens to the implicitly concatenated strings, I suggest Black not removing them as the parens are indications of needing to wrap the string to increase readability.

This might be not necessary if Black chooses to use explicit str concatenations (#2553).

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: parenthesesToo many parentheses, not enough parentheses, and so on.F: stringsRelated to our handling of stringsT: styleWhat do we want Blackened code to look like?

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions