pythonpython-black

How to prevent black adding parentheses for chain of code


Given code:

longfunc(long_arg1, long_arg2...).longfunct().longfunct().longfunct()

How can I prevent black wrapping it in parentheses?

(
 longfunc(long_arg1, long_arg2...)
.longfunct()
.longfunct()
.longfunct()
)

What rule enforces that?


Solution

  • This is a Call Chain and the behavior is specified in the documentation. Each call is broken into a line for consistent readability and diffs. This adds new lines which would need to be escaped - a no-no for black - or wrapped in parens. This is a purposeful feature and I doubt it will change.