Open jleclanche opened 6 years ago
Did you miss some of the list elements after the (21,
in the output above?
As for the time it takes, it's probably simply that the data literal has a lot of elements in it and the number of permutations is large...:-/
I didn't miss it, scroll to the side :)
The weird thing is that the two tuple representations are syntactically the same, and yapf should be deciding whether or not the tuple should be represented as a vertical list with trailing commas, or inline list without.
That's ideally what YAPF should be doing, but there's probably some heuristic getting in the way...
@gwelymernans any idea what's causing it?
The issue is not limited in tuples, I get the same strange behavior with list of lists. E.g.:
% cat test.py
list_of_lists = [
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2]
]
% yapf test.py
list_of_lists = [[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2],
[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2],
[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2]]
vs.
% cat test.py
list_of_lists = [
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2],
[1, 2]
]
% yapf test.py
list_of_lists = [[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2],
[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2],
[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1,
2], [1, 2]]
It's definitely a penalty problem. The penalty for splitting between elements of a list is 0
even if the list (or other container) is an element of another list.
Test case:
Write the following file to
foo.py
(note the tab indents):With the following style:
Gets turned into this:
And yet, if I add a trailing comma at the end of the list of tuples (right after
(27, "UNGORO")
), it becomes this (which is the intended style):Also note that it's much faster. Yapf is super slow at formatting the former; the difference is in several hundreds of ms.