Prefer splitting expressions with many child expressions. · Issue #1811 · psf/black (original) (raw)
Describe the style change
Currently black splits lines from the outermost expression to the innermost expression. This makes sense in most cases, but there is some cases where preferring the inner expression is more semantic. This is especially true if the only argument of a function is a dictionary.
Examples in the current Black style
f( { "foo": "This is a dict", "bar": "with values that are too long", "baz": "to fit on a line.", } )
Desired style
f({ "foo": "This is a dict", "bar": "with values that are too long", "baz": "to fit on a line.", })
In this example the first break (putting the dict on it’s own line) doesn’t even make the lines any shorter.
Additional context
It’s hard to make a general rule out of this. Perhaps splitting expressions first that have many child-expresssions would be a reasonable heuristic, but I’m happy for suggestions.