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
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.
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_.