Comprehensions format incorrectly
- Dominant language
- Python
- Stars
- 14k
- Forks
- 904
- PR merge metrics
- No merged PRs in 30d
Description
I'm using yapf 0.30.0 with `based_on_style = google` (nothing else in the `.style.yapf`).
The following example is from [2.7 Comprehension & Generator Expressions](https://google.github.io/styleguide/pyguide.html#27-comprehensions--generator-expressions) of the Google Python Style Guide:
```python
# original
result = [{'key': value} for value in iterable
if a_long_filter_expression(value)]
# yapf'ed
result = [{
'key': value
} for value in iterable if a_long_filter_expression(value)]
```
This is not compliant with the style guide in use (I expected no change), nor is it ideal. When replacing the dictionaries with `some_expression`, I get another unexpected format:
```python
# original
result = [some_expression for value in iterable
if a_long_filter_expression(value)]
# yapf'ed
result = [
some_expression for value in iterable if a_long_filter_expression(value)
]
```
The same problems occur with other types of comprehensions.
Is this expected behavior, or a bug? I suspect that it's a bug, as I haven't been able to find any knob that would change this behavior. If I'm wrong, could you kindly tell me which knob to turn to get the result I expect?
Contributor guide
Assessment
This issue has not been assessed yet.