black
black copied to clipboard
number list or number array style
Describe the style change
Examples in the current Black style
compare = torch.tensor(
[
[
[
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
]
]
]
)
Desired style
compare = torch.tensor([[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0]]])
Additional context
I think the number list or number array let it keep square is better to read.
Maybe it could be a different rule for (deeply?) nested lists. Or potentially just allowing this as an alternative. I agree the first example looks messy
Another idea is a vertical limit before the contents of the list stop being expanded in that way.
I think, for a list, if it fill the line firstly, then turn to the next line. I think this will be better. I means it don't need wrap after each comma, according to the maximum number of characters in a line may be better.
This is a pretty common ask, e.g. see https://github.com/psf/black/issues/1281
Your best workaround right now is # fmt: off/on
(fwiw this kind of thing is by far the most common reason I see use of # fmt: off / on
)
Thank you for the suggestion, but unfortunately we won't do this. For your particular example it is a lot more readable, but it is not a style we want to have in general or guess when it is appropriate over the ordinary item-per-line style. # fmt: off/on
is a good solution here.