Yapf gets confused with a long list of tuples
- Dominant language
- Python
- Stars
- 14k
- Forks
- 904
- PR merge metrics
- No merged PRs in 30d
Description
Test case:
Write the following file to `foo.py` (note the tab indents):
```py
(
[
(0, "INVALID"), (1, "TEST_TEMPORARY"), (2, "CORE"), (3, "EXPERT1"), (4, "HOF"),
(5, "MISSIONS"), (6, "DEMO"), (7, "NONE"), (8, "CHEAT"), (9, "BLANK"), (10, "DEBUG_SP"),
(11, "PROMO"), (12, "NAXX"), (13, "GVG"), (14, "BRM"), (15, "TGT"), (16, "CREDITS"),
(17, "HERO_SKINS"), (18, "TB"), (19, "SLUSH"), (20, "LOE"), (21, "OG"), (22, "OG_RESERVE"),
(23, "KARA"), (24, "KARA_RESERVE"), (25, "GANGS"), (26, "GANGS_RESERVE"), (27, "UNGORO")
],
)
```
With the following style:
```toml
[yapf]
ALIGN_CLOSING_BRACKET_WITH_VISUAL_INDENT = false
ALLOW_MULTILINE_LAMBDAS = false
ALLOW_MULTILINE_DICTIONARY_KEYS = false
BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF = false
BLANK_LINE_BEFORE_CLASS_DOCSTRING = false
COALESCE_BRACKETS = false
COLUMN_LIMIT = 92
CONTINUATION_INDENT_WIDTH = 1
DEDENT_CLOSING_BRACKETS = true
EACH_DICT_ENTRY_ON_SEPARATE_LINE = true
INDENT_DICTIONARY_VALUE = false
INDENT_WIDTH = 1
JOIN_MULTIPLE_LINES = true
USE_TABS = true
SPACES_AROUND_DEFAULT_OR_NAMED_ASSIGN = false
SPACES_BEFORE_COMMENT = 2
```
Gets turned into this:
```py
(
[
(0, "INVALID"), (1, "TEST_TEMPORARY"), (2, "CORE"), (3, "EXPERT1"), (4, "HOF"),
(5, "MISSIONS"), (6, "DEMO"), (7, "NONE"), (8, "CHEAT"), (9, "BLANK"), (10, "DEBUG_SP"),
(11, "PROMO"), (12, "NAXX"), (13, "GVG"), (14, "BRM"), (15, "TGT"), (16, "CREDITS"),
(17, "HERO_SKINS"), (18, "TB"), (19, "SLUSH"), (20, "LOE"), (21,
"OG"), (22, "OG_RESERVE"),
(23, "KARA"), (24, "KARA_RESERVE"), (25, "GANGS"), (26, "GANGS_RESERVE"), (27, "UNGORO")
],
)
```
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):
```py
(
[
(0, "INVALID"),
(1, "TEST_TEMPORARY"),
(2, "CORE"),
(3, "EXPERT1"),
(4, "HOF"),
(5, "MISSIONS"),
(6, "DEMO"),
(7, "NONE"),
(8, "CHEAT"),
(9, "BLANK"),
(10, "DEBUG_SP"),
(11, "PROMO"),
(12, "NAXX"),
(13, "GVG"),
(14, "BRM"),
(15, "TGT"),
(16, "CREDITS"),
(17, "HERO_SKINS"),
(18, "TB"),
(19, "SLUSH"),
(20, "LOE"),
(21, "OG"),
(22, "OG_RESERVE"),
(23, "KARA"),
(24, "KARA_RESERVE"),
(25, "GANGS"),
(26, "GANGS_RESERVE"),
(27, "UNGORO"),
],
)
```
Also note that it's *much* faster. Yapf is super slow at formatting the former; the difference is in several hundreds of ms.
Contributor guide
Assessment
This issue has not been assessed yet.