black icon indicating copy to clipboard operation
black copied to clipboard

number list or number array style

Open Vincent0706 opened this issue 1 year ago • 3 comments

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.

Vincent0706 avatar Jul 22 '22 07:07 Vincent0706

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.

dignissimus avatar Jul 22 '22 07:07 dignissimus

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.

Vincent0706 avatar Jul 22 '22 14:07 Vincent0706

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)

hauntsaninja avatar Jul 25 '22 21:07 hauntsaninja

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.

felix-hilden avatar Aug 15 '22 20:08 felix-hilden