black icon indicating copy to clipboard operation
black copied to clipboard

Indexing square brackets split on 3 lines

Open ikamensh opened this issue 3 years ago • 1 comments

Describe the style change I have an assert statement that checks a condition on the last element in an array. To me what black does to the statement makes it less readable:

assert self.ref_transitions[-1].terminal.all(), "Last ref transition must be terminal."

Examples in the current Black style

assert self.ref_transitions[
    -1
].terminal.all(), "Last ref transition must be terminal."

Desired style

assert (
    self.ref_transitions[-1].terminal.all()
), "Last ref transition must be terminal."

# OR

assert self.ref_transitions[-1].terminal.all(), (
    "Last ref transition must be terminal."
)

Additional context

I think operation of taking [-1]th element is best visible with brackets and number grouped. Having to search them across a diagonal on 3 lines is tough.

ikamensh avatar May 11 '22 09:05 ikamensh

Hi! The bracket break is tracked in #236, and assert formatting in #348. Therefore this could be considered a duplicate, if you think they satisfy your style proposal!

felix-hilden avatar May 11 '22 09:05 felix-hilden

As @felix-hilden said this is a duplicate of various older issues.

JelleZijlstra avatar Dec 20 '22 02:12 JelleZijlstra