google / google/yapf

Inconsistent line splitting when function argument is a dictionary

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

Description

When formatting the code below with `yapf --style=pep8`:
```python
if a:
if b:
if e.response.get('Error', {}).get('XXXX')[0] == '4' and e.xxxxxxxxx_xxxx == 'XXXXXXXXXX':
pass

if a:
if b:
if e.response.get('Error', xy).get('XXXX')[0] == '4' and e.xxxxxxxxx_xxxx == 'XXXXXXXXXX':
pass
```
produces

```python
if a:
if b:
if e.response.get(
'Error',
{}).get('XXXX')[0] == '4' and e.xxxxxxxxx_xxxx == 'XXXXXXXXXX':
pass

if a:
if b:
if e.response.get(
'Error',
xy).get('XXXX')[0] == '4' and e.xxxxxxxxx_xxxx == 'XXXXXXXXXX':
pass
```

which is inconsistent, as in the first case the dictionary has a different indentation as the `xy` variable.

Also, the generated code has the following PEP8 violations:

```
test2.py:5:5: E129 visually indented line with same indent as next logical line
test2.py:5:13: E131 continuation line unaligned for hanging indent
```

yapf version: 0.22.0

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.