[Python-ideas] PEP8 operator must come before line break
SW
walker_s at hotmail.co.uk
Thu Apr 14 12:25:56 EDT 2016
Hi,
PEP8 says that: "The preferred place to break around a binary operator
is after the operator, not before it."
This is ignored in the multiline if examples, and seems to generally be
a bad idea as it negatively impacts clarity.
For example, the following seems much clearer as the entire line does
not need to be scanned to see the intent- only the start of the line is
needed to see how the different properties are used for filtering:
mylist = [
item for item in mylist
if item['property'] == 2
and item['otherproperty'] == 'test'
]
The alternative seems less clear:
mylist = [
item for item in mylist
if item['property'] == 2 and
item['otherproperty'] == 'test'
]
If this recommendation remains in force, it would be good to:
1. Follow it in the style guide.
2. Provide a rationale for it, as currently it seems arbitrary and
unhelpful.
Just raising this as it has bitten me a couple of times with style
checkers recently.
Thanks,
S
More information about the Python-ideas
mailing list