black icon indicating copy to clipboard operation
black copied to clipboard

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

Open yilei opened this issue 3 years ago • 1 comments

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 https://github.com/psf/black/pull/3162#issuecomment-1228778654). 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).

yilei avatar Sep 06 '22 22:09 yilei

I'd be open to keeping them, or even going all the way. But I understand that diffs getting larger is awkward.

felix-hilden avatar Sep 11 '22 14:09 felix-hilden

This is obsoleted by #3292 (implemented in #3307).

yilei avatar Dec 15 '22 06:12 yilei