google / google/yapf

Inconsistent results with SPLIT_COMPLEX_COMPREHENSION

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

Description

I created a small example file, which I'd like the formatter to leave alone when `SPLIT_COMPLEX_EXPRESSION` is true, but unfortunately it does not.

If you create a file with the contents,

```py
dat_files = [
filename
for input_dir in args.input_dirs
for filename in glob.glob(os.path.join(input_dir, "*.DAT"))
]
```

and then run `yapf --style='{SPLIT_COMPLEX_COMPREHENSION: true}'` on it, the comprehension value and first `for` loop are joined,

```py
dat_files = [
filename for input_dir in args.input_dirs
for filename in glob.glob(os.path.join(input_dir, "*.DAT"))
]
```

Unfortunately this doesn't make much sense, because `filename` is more associated with the inner loop, and having it right next to the outer loop (`for input_dir in args.input_dirs`) is messier.

However, the example on the main README.rst for SPLIT_COMPLEX_EXPRESSION does provide desired results ... so maybe there is an issue with the ordering of transformers or something.

Thanks!!

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.