google / google/yapf

Formatting list comprehensions

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

Description

My suggestion is the following:
1. break in expression* => break the for ~~and the if (edit: this is implied by 2.)~~.
2. break the for => break the if.

*This should add a continued_indent.

.1. seems obvious to me, I can see 2. being slightly more controversial...

To give a silly example:

```
# current
["This is a list comprehension which is quite long, I want it to split" +
"a second long string pushes this over 79" for i in range(3) if i == 1]

# one possible
["This is a list comprehension which is quite long, I want it to split" +
"a second long string pushes this over 79"
for i in range(3) if i == 1]

# my suggestion
["This is a list comprehension which is quite long, I want it to split" +
"a second long string pushes this over 79"
for i in range(3)
if i == 1]

# autopep8
["This is a list comprehension which is quite long, I want it to split" +
"a second long string pushes this over 79" for i in range(3) if i == 1]
```

I realise @gwelymernans is [working on list comprehensions](https://github.com/google/yapf/commit/140c229dc82e100ed2ff1ac5688be26c92b38792), but thought I should punt this as an issue.

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.