google / yapf

A formatter for Python files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] yapf with split_all_top_level_comma_separated_values set to true fails to split lines with tuple LHS

dnns92 opened this issue · comments

Dear yapf-team,

for this code snippet, one would expect to receive a roughly same treatment of these two statements:

test.py

x, = some_long_enough_function_to_cause_a_linebreak(very_long_arg1, very_long_arg_2, an_extemly_loooooooooooooooooooooooong_argument)
x = some_long_enough_function_to_cause_a_linebreak(very_long_arg1, very_long_arg_2, an_extemly_looooooooooooooooooooooooong_argument)

However, after running yapf --style .\.style.yapf -rip test.py with the .style.yapf:

[style]
based_on_style = pep8
column_limit = 120
split_all_top_level_comma_separated_values = true

We receive:

x, = some_long_enough_function_to_cause_a_linebreak(very_long_arg1, very_long_arg_2, an_extemly_loooooooooooooooooooooooong_argument)

x = some_long_enough_function_to_cause_a_linebreak(very_long_arg1,
                                                   very_long_arg_2,
                                                   an_extemly_loooooooooooooooooooooooong_argument)

Expectation:

x, = some_long_enough_function_to_cause_a_linebreak(very_long_arg1,
                                                    very_long_arg_2,
                                                    an_extemly_looooooooooooooooooooooooong_argument)

x = some_long_enough_function_to_cause_a_linebreak(very_long_arg1,
                                                   very_long_arg_2,
                                                   an_extemly_loooooooooooooooooooooooong_argument)

I experimented a bit and saw that this issue arises only when split_all_top_level_comma_separated_values is true. This cannot be fixed by using syntax like x, _ = or x, y = . A workaround is however to put enclosing brackets around the LHS like (x,) = or (x, _) = .

However, the fix seems to produce this weird effect as well:

(x111, y222) = my_very_long_call_bla(my_very_long_arg, my_very_long_arg, my_very_long_arg, my_very_looooooooooooooong_arg)

turns into

(x111,
 y222) = my_very_long_call_bla(my_very_long_arg, my_very_long_arg, my_very_long_arg, my_very_looooooooooooooong_arg)

instead of how one would expect it:

(x111, y222) = my_very_long_call_bla(
    my_very_long_arg, my_very_long_arg, my_very_long_arg, my_very_looooooooooooooong_arg
)

Was there any progress on this issue?