You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One things that's bugged me about black for a while is the way it handles the multiline formatting for binary operators when their operands are function calls. The case that most frequently occurs for me is in if statements. Consider the unformatted code below:
I end up passing over the content in the middle because:
The arguments of the second function stands out and draw my attention
This is a common reformatting pattern for other function calls that do not have operators on the same line
Further, even if you're someone who is able to read this correctly, this reformatting isn't "symetric" (for lack of a better word). Putting each operand of or into its own line would improve the aesthetics a great deal:
if (
some_function(an_argument)
orsome_other_function(another_argument, yet_another_argument)
):
...
Yes, it takes up an extra line or two, but using more lines doesn't cost you anything, and I think the easier readability/aesthetic benefit is substantial. It's also worth noting that this form is what black adopts as soon as you add one more operator into the equation. For example, given the following unformatted code:
So adopting the proposed strategy for reformatting conditions described above would also help with the consistency too since there would only be one way to reformat in either scenario.
One things that's bugged me about
black
for a while is the way it handles the multiline formatting for binary operators when their operands are function calls. The case that most frequently occurs for me is inif
statements. Consider the unformatted code below:Presently
black
will reformat this in the following way:When I skim over the code above, I tend to read it a little like this:
I end up passing over the content in the middle because:
Further, even if you're someone who is able to read this correctly, this reformatting isn't "symetric" (for lack of a better word). Putting each operand of
or
into its own line would improve the aesthetics a great deal:Yes, it takes up an extra line or two, but using more lines doesn't cost you anything, and I think the easier readability/aesthetic benefit is substantial. It's also worth noting that this form is what black adopts as soon as you add one more operator into the equation. For example, given the following unformatted code:
black
will reformat it into the more pleasing form:So beyond trying to reduce the number of lines in a file, it's not clear to me what the benefit of this form is:
The text was updated successfully, but these errors were encountered: