google / google/yapf

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

Open
#1,203 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
14k
Forks
904
PR merge metrics
No merged PRs in 30d

Description

Dear yapf-team,

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

test.py
~~~python
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`:
~~~text
[style]
based_on_style = pep8
column_limit = 120
split_all_top_level_comma_separated_values = true
~~~

We receive:

~~~python
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:

~~~python
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:
~~~python
(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

~~~python
(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:
~~~python
(x111, y222) = my_very_long_call_bla(
my_very_long_arg, my_very_long_arg, my_very_long_arg, my_very_looooooooooooooong_arg
)
~~~

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.