Formatting of conditional expressions in named function arguments #2248
Labels
F: parentheses
Too many parentheses, not enough parentheses, and so on.
T: style
What do we want Blackened code to look like?
When formatting conditional expressions in function calls with named arguments, Black's formatting varies significantly depending on whether the expression is surrounded by parenthesis.
Exhibit A:
Black considers this correctly formatted
Exhibit B
When fed the following block as input:
Black formats it with a much nicer indentation
I consider the second output far more readable. In exhibit A the
if
expression lies on the same indent as the kwargs, making it hard to tell what's going on. In the second, it's quite clear that some computation is spanning those three lines.I think ideally Black would never produce Exhibit A, rather it would insert the parenthesis in order to indent the conditional expression.
In keeping with the opinionated style, we should pick one or the other, but probably not allow both. Even if Black decided to strip parenthesis and produce exhibit A all of the time, it'd be preferable to the current ambiguity.
The text was updated successfully, but these errors were encountered: