[Python-ideas] PEP8 operator must come before line break

Ian Lee ianlee1521 at gmail.com
Thu Apr 14 15:25:20 EDT 2016


My preference has been towards having the binary operator at the front rather than end since listening to Brandon Rhodes 2012 PyCon Canada talk (specifically starting around [1]) . Specifically he is arguing that following Knuth rather than PEP 8 [2] might be a better way to go.

Maybe my preference there is due to the Django work I was doing where I would get long query lines and didn’t always want to split them into multiple lines [3]:

query = (Person.objects
    .filter(last_name==‘Smith’)
    .order_by('social_security_number')
    .select_related('spouse')
    )

[1] http://rhodesmill.org/brandon/slides/2012-11-pyconca/#id183 <http://rhodesmill.org/brandon/slides/2012-11-pyconca/#id183>
[2] http://rhodesmill.org/brandon/slides/2012-11-pyconca/#knuth-instead-of-pep-8 <http://rhodesmill.org/brandon/slides/2012-11-pyconca/#knuth-instead-of-pep-8>
[3] http://rhodesmill.org/brandon/slides/2012-11-pyconca/#option-3 <http://rhodesmill.org/brandon/slides/2012-11-pyconca/#option-3>

~ Ian Lee | IanLee1521 at gmail.com <mailto:IanLee1521 at gmail.com>
> On Apr 14, 2016, at 11:48, SW <walker_s at hotmail.co.uk> wrote:
> 
> That'll teach me for stepping away from the computer...
> 
> As for changing an established rule, I agree that can be difficult. The
> reason this one became an irritation for me is that it was only in the
> last few months that I saw flake8 (my style complainer of choice) start
> complaining about this, so it's not quite so entrenched as other
> elements of style.
> 
> I agree that placing the binary operator at the end shows the line
> should continue, and thus could be valid, but I also think that placing
> it at the start of the next line shows the logic flow for each part of
> the expression more clearly- as shown in the examples I originally gave.
> 
> Thanks,
> S
> 
> On 14/04/16 18:23, Guido van Rossum wrote:
>> Thanks, that was obviously an oversight. I've fixed the PEP.
>> 
>> If the discussion ends up with rough consensus on changing this I will
>> happily change it back (and change all other occurrences to match the
>> new rule).
>> 
>> Note that my request for "rough consensus" does *not* imply a vote. +1
>> and -1 votes (nor fractions in between) should not be posted --
>> however cogent arguments for/against the status quo (or for
>> relinquishing the rule altogether) are welcome.
>> 
>> On Thu, Apr 14, 2016 at 10:02 AM, Matthias welp <boekewurm at gmail.com> wrote:
>>>> Where in PEP 8 does it violate its own advice
>>> As the OP did not reply this fast, from the webpage (/dev/peps/pep-0008)
>>> 
>>> section indentation, just after 'Acceptable options in this situation
>>> include, but are not limited to: '
>>> 
>>> # Add some extra indentation on the conditional continuation line.
>>> if (this_is_one_thing
>>>        and that_is_another_thing):
>>>    do_something()
>>> 
>>> That is the only place I could find just now.
>>> 
>>> 
>>> _______________________________________________
>>> Python-ideas mailing list
>>> Python-ideas at python.org
>>> https://mail.python.org/mailman/listinfo/python-ideas
>>> Code of Conduct: http://python.org/psf/codeofconduct/
>> 
>> 
> 
> 
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160414/3a10d41e/attachment-0001.html>


More information about the Python-ideas mailing list