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