black
black copied to clipboard
Black fails to keep within line length limit when using named parameters
Describe the bug
If a long named parameter expression is passed to a function call, black exceeds the line length limit. Adding parentheses fixes the issue, but it feels like Black should do that automatically.
To Reproduce
foo(
this_is_a_very_looooooooooooooong_parameter_name=some_very_loooooooooooooooooong_variable_name
)
Expected output
foo(
this_is_a_very_looooooooooooooong_parameter_name=(
some_very_loooooooooooooooooong_variable_name
)
)
Which stays within the 88-character line length limit.
Actual output
foo(
this_is_a_very_looooooooooooooong_parameter_name=some_very_loooooooooooooooooong_variable_name
)
Which exceeds the 88-character line length limit.
Workaround
The issue can be worked around by adding the parentheses manually and then running black.
Additional information
Worth noting this appears to be specific to named parameters, and does not affect, say variable assignments. Indeed, the following:
this_is_a_very_looooooooooooooong_parameter_name=some_very_loooooooooooooooooong_variable_name
Is correctly formatted to:
this_is_a_very_looooooooooooooong_parameter_name = (
some_very_loooooooooooooooooong_variable_name
)
Black's behaviour appears to be inconsistent between variable assignments and named parameters in this regard.