Yapf: Add style for multiline comprehensions

Created on 9 Sep 2016  路  8Comments  路  Source: google/yapf

If a comprehension can't fit on one line, splitting it to multiple lines on comprehension specific things would be good.

foo = [
    some_func(value)
    for value in a_long_named_iterable
    if some_condition(value)
    and not bad_thing(value)
]

Right now it's collecting the for .. in .. if all in one line rather than splitting them

Most helpful comment

I think this issue is still open. It sounds like #470 addressed _where_ to split a long comprehension but does not allow forcing a complex comprehension to be split _regardless of length_.

All 8 comments

This seems related to binpacking long lines in general, I'll see if I can make a larger issue about that

We kind of try to do this, at least a bit. The heuristic may need some tweaking though. But yeah, it's having to do with bin packing in general.

I think #470 and the introduction of SPLIT_COMPLEX_COMPREHENSION might fix this issue.

What @msuozzo said. :-) Please try it with HEAD and let me know if it works for you.

I think this issue is still open. It sounds like #470 addressed _where_ to split a long comprehension but does not allow forcing a complex comprehension to be split _regardless of length_.

@tilgovi Right. All that YAPF does is based on heuristics. The best we could do is add a knob to allow people to modify the heuristics...

This is still an issue -- having single lines get packed should be a knob

馃憤 on this. Perhaps a knob for favoring shorter lines up to some limit would help. Or a knob simply enforcing that comprehensions are always split.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

prokher picture prokher  路  7Comments

jamesqo picture jamesqo  路  5Comments

lexicalunit picture lexicalunit  路  9Comments

eli-schwartz picture eli-schwartz  路  5Comments

qv-pat picture qv-pat  路  3Comments