Can the python black formatter nest long lists and sets? For example:
Input
coworkers = {"amy", "bill", "raj", "satoshi", "jim", "lifeng", "jeff", "sandeep", "mike"}
Default output
coworkers = {
"amy",
"bill",
"raj",
"satoshi",
"jim",
"lifeng",
"jeff",
"sandeep",
"mike",
}
Desired output
coworkers = {
"amy", "bill", "raj", "satoshi", "jim",
"lifeng", "jeff", "sandeep", "mike",
}
This is not possible, because the coding style used by Black can be viewed as a strict subset of PEP 8. Please read docs here. Specifically:
As for vertical whitespace, Black tries to render one full expression or simple statement per line. If this fits the allotted line length, great.
# in: j = [1, 2, 3 ] # out: j = [1, 2, 3]
If not, Black will look at the contents of the first outer matching brackets and put that in a separate indented line.
# This piece of code is written by me, it isn't part of the original doc # in j = [1, 2, 3, 4, 5, 6, 7] # out j = [ 1, 2, 3, 4, 5, 6, 7 ]
If that still doesn’t fit the bill, it will decompose the internal expression further using the same rule, indenting matching brackets every time. If the contents of the matching brackets pair are comma-separated (like an argument list, or a dict literal, and so on) then Black will first try to keep them on the same line with the matching brackets. If that doesn’t work, it will put all of them in separate lines.