I am using black to format my python code. I observed the following behavior. I admit that it is a very specific case but it goes on my nerves.
Let's suppose I have the following code:
@pytest.mark.parametrize(
"first",
["second"],
)
black does not change that. But, if I remove the trailing comma after ["second"]:
@pytest.mark.parametrize(
"first",
["second"]
)
black makes a nice reordering:
@pytest.mark.parametrize("first", ["second"])
On the other hand, let us see the following:
@pytest.mark.parametrize(
"This is a very long line. Black will not be able to to a linebreak here.",
["second"],
)
In this case, again, black does not change anything. So far, so good. Now, I remove the trailing comma after ["second"] again:
@pytest.mark.parametrize(
"This is a very long line and black will not be able to do a line break here.",
["second"]
)
As the line is too long, black does not do a nice reordering into one line as before. But instead, black adds a trailing comma after the ["second"]:
@pytest.mark.parametrize(
"This is a very long line and black will not be able to do a line break here.",
["second"],
)
I do not like that. When I am confronted with such lists in my code, I always tend to remove the trailing comma to enforce one line reordering. But then, in most of the cases, black adds it again ...