<div dir="ltr"><div><div>After a fruitful discussion on python-ideas I've decided that it's fine to break lines *before* a binary operator. It looks better and Knuth recommends it.<br></div><br></div>The head of the python-ideas discussion: <a href="https://mail.python.org/pipermail/python-ideas/2016-April/039752.html">https://mail.python.org/pipermail/python-ideas/2016-April/039752.html</a><br><div><div><div><br>See also the discussion in the tracker: <a href="http://bugs.python.org/issue26763">http://bugs.python.org/issue26763</a><br><br>Here's the diff I applied: <a href="https://hg.python.org/peps/rev/3857909d7956">https://hg.python.org/peps/rev/3857909d7956</a><br><br></div><div>The talk by Brandon Rhodes where Knuth is referenced ([3] below): <a href="http://rhodesmill.org/brandon/slides/2012-11-pyconca/#laying-down-the-law">http://rhodesmill.org/brandon/slides/2012-11-pyconca/#laying-down-the-law</a><br></div><div><br>The key section in PEP 8 that was updated (apart from fixing up references):<br><br><span style="font-family:monospace,monospace">Should a line break before or after a binary operator?<br>------------------------------------------------------<br><br>For decades the recommended style has been to break after binary<br>operators.  However, recent reseach unearthed recommendations by<br>Donald Knuth to break *before* binary operators, in his writings about<br>typesetting [3]_.  Therefore it is permissible to break before or<br>after a binary operator, as long as the convention is consistent<br>locally.  For new code Knuth's style is suggested.<br><br>Some examples of code breaking before binary Boolean operators::<br><br>    class Rectangle(Blob):<br><br>        def __init__(self, width, height,<br>                     color='black', emphasis=None, highlight=0):<br>            if (width == 0<br>                and height == 0<br>                and color == 'red'<br>                and emphasis == 'strong'<br>                or highlight > 100):<br>                raise ValueError("sorry, you lose")<br>            if (width == 0 and height == 0<br>                and (color == 'red' or emphasis is None)):<br>                raise ValueError("I don't think so -- values are %s, %s" %<br>                                 (width, height))<br>            Blob.__init__(self, width, height,<br>                          color, emphasis, highlight)<br></span><br><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)</div></div></div></div>