autopep8
autopep8 copied to clipboard
Unfortunate E501 fix for list comprehension
Python Code
# example.py
[very_long_item_name for very_long_item_name in function(something) if condition]
Result
[very_long_item_name for very_long_item_name in function(
something) if condition]
This is hard to read. Even if function
has more arguments, this looks confusing to me. I would have expected any of the following (depending on the length of function(something)
and condition
):
# Better solution?
[very_long_item_name for very_long_item_name
in function(something) if condition]
# ... or?
[very_long_item_name for very_long_item_name in
function(something) if condition]
# For long `function(something)` or `condition`?
[very_long_item_name
for very_long_item_name
in function(something)
if condition]
# ...or?
[very_long_item_name for
very_long_item_name in
function(something) if
condition]
(I prefer the first and third solution.) Or is this a situation where the "correct" solution is to rewrite the comprehension using loops?
Command Line and Configuration
No configuration.
Command Line
$ autopep8 example.py
Your Environment
- Python version: Python 3.7.8
- autopep8 version: autopep8 1.5.5 (pycodestyle: 2.6.0)
- Platform: macOS 11.2.1