google / google/yapf

Is it possible to avoid double-indentation of long arglists when using split_before_first_argument=True and dedent_closing_brackets=True?

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

Description

If you have `split_before_first_argument=True` set and a long function call, then yapf uses a *double* indent for the arguments:

```python
def foobar(
a,
b,
c):
pass
```

This is clearly necessary when `dedent_closing_brackets=False`, as in the example above, because if you used a single indent you'd get this unreadable thing:

```python
def foobar(
a,
b,
c):
pass
```

However, if using `dedent_closing_brackets=True`, we get
```python
def foobar(
a,
b,
c
):
pass
```
and in this case, the extra indentation is both pointless and somewhat distracting. It seems more natural to write:
```python
def foobar(
a,
b,
c
):
pass
```

Is there any way to tell yapf to work this way? If not, then could there be?

(Cf. #458 concerns how `async def` used to accidentally do what I'm requesting here, #459 which fixes the bug that triggered #458 and makes `async def` and `def` consistently do the double-indentation thing, and https://github.com/python-trio/trio/issues/334)

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.