google / yapf

A formatter for Python files
Apache License 2.0
13.76k stars 890 forks source link

Inconsistent line splitting - tuple vs list #549

Open kamahen opened 6 years ago

kamahen commented 6 years ago

I changed my __slots__ assignments from tuple to list (I got tired of accidentally leaving out the trailing comma in singleton tuples, and to my surprise yapf formatted them differently. Is there a knob for avoiding this? (I would have expected this yapf behavior if I had had a trailing comma ... I tried flipping the setting for coalesce_brackets, but that didn't help.

    __slots__ = ('for_astn', 'for_exprlist', 'in_testlist', 'comp_iter',
        'scope_bindings')

vs

    __slots__ = [
        'for_astn', 'for_exprlist', 'in_testlist', 'comp_iter',
        'scope_bindings'
    ]

And here are the diffs from the default style:

3c3
< align_closing_bracket_with_visual_indent=True
---
> align_closing_bracket_with_visual_indent=False
37c37
< blank_line_before_nested_class_or_def=False
---
> blank_line_before_nested_class_or_def=True
119c119
< indent_dictionary_value=False
---
> indent_dictionary_value=True
160c160
< split_before_closing_bracket=True
---
> split_before_closing_bracket=False
181c181
< split_before_logical_operator=True
---
> split_before_logical_operator=False
200c200
< split_complex_comprehension=False
---
> split_complex_comprehension=True
203c203
< split_penalty_after_opening_bracket=30
---
> split_penalty_after_opening_bracket=-100
224c224
< split_penalty_for_added_line_split=30
---
> split_penalty_for_added_line_split=300
bwendling commented 6 years ago

Tuples are treated differently from lists and dicts / sets. There's no good reason for it, except that function definitions / calls kind of look like tuples to YAPF. This is a long standing issue that I would like to resolve though.

kamahen commented 6 years ago

The split_before_closing_bracket seems a bit strange -- it seems to ignore a trailing ,. Is that intended behavior?