question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add style for multiline comprehensions

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:7
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
tilgovicommented, Feb 28, 2018

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.

1reaction
rgangopadhyacommented, Apr 2, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pythonic Style for Multiline List Comprehension - Stack Overflow
PEP 8 kinda predates list comprehensions. I usually break these up over multiple lines at logical locations: memberdef_list = [elem for elem ...
Read more >
Overusing list comprehensions and generator expressions in ...
In general, I prefer to write most of my comprehensions spaced out over multiple lines of code using the indentation style above.
Read more >
Comprehensive Guide to Python List Comprehensions
This comprehensive guide to Python list comprehensions talks about the syntax, different forms, comparison to map, filter, ...
Read more >
comprehensions poor formatting · Issue #733 · psf/black - GitHub
I will look into this but this is hard to get right. If the auto-formatter fails to format very complex expressions, I'd suggest...
Read more >
Avoid More Than Two Expressions in List Comprehensions
The rule of thumb is to avoid using more than two expressions in a list comprehension. This could be two conditions, two loops,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found