google / google/yapf

Bad formatting for recursive list and named parameter in function call

Open
#729 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
14k
Forks
904
PR merge metrics
No merged PRs in 30d

Description

Hi again!

Some of my code base has some recursive list and named parameter in function calls.
```python
def foo(mattrix_var):
foo_result = calc_function([
calc_function([1 / 100 * mattrix_var[:, :, 1, 1],
1 / 100 * mattrix_var[:, :, 1, 0]], key=1),
calc_function([1 / 100 * mattrix_var[:, :, 0, 1],
1 / 100 * mattrix_var[:, :, 0, 0]], key=2)],
key=3)
return foo_result
```

After formatting with yapf version 0.27.0, the result looks not interested:
```python
def foo(mattrix_var):
foo_result = calc_function([
calc_function([
1 / 100 * mattrix_var[:, :, 1, 1],
1 / 100 * mattrix_var[:, :, 1, 0]
],
key=1),
calc_function([
1 / 100 * mattrix_var[:, :, 0, 1],
1 / 100 * mattrix_var[:, :, 0, 0]
],
key=2)
],
key=3)
return foo_result
```

Well, I don't know what is the best formatting for the code like this, but the current formatting clearly looks not good, especially the closing bracket `],` and the next level of indentation for the `key=2` and `key=3`.
Is there a better formatting for this?
Thank you!

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.