black
black copied to clipboard
don't split binary operation if right operand is a function call with short name
Describe the style change
Don't add linebreak in binary operations if right operand is a function with short name and long body. Instead prefer keeping function call on the same line and moving function body to next lines.
Examples in the current Black style
f(
a
/ f( # <- this feels weird
x=x,
),
)
a / f( # <- this is fine
x=x,
)
Desired style
f(
a / f( # <- no linebreak
x=x,
),
)
a / f( # <- unchanged
x=x,
)
Additional context
Looks like this happens in all "parenthesised" items lists (like list literal, function call, etc...), but not in "global" context.
This happens with all binary operators, not only with /
.
Preview mode didn't help.
I experienced this while using construct
library:
Var = c.Struct(
'name' / WStr,
'type'
/ c.Enum( # <- inconsistent with all other declarations
u8,
unknown=0,
int=1,
dword=2,
float=3,
str=4,
array=9,
),
'value'
/ c.Switch( # <- same
c.this.type,
{
'unknown': c.Computed(None),
'int': i32,
'dword': u32,
'float': f64,
'str': WStr,
'array': List(u32),
},
),
)
This might be helpful (with default --line-length
which defaults to 88
). All long names are as short as possible to force the corresponding style:
f(
a / f(_76chars____________________________________________________________________),
)
f(
a
/ f(_77chars_____________________________________________________________________),
)
f(
a
/ f(
_79chars_______________________________________________________________________
),
)