This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Illustrate both binary operator conventions in PEP-8
Type: enhancement Stage: resolved
Components: Documentation Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: barry, brandon-rhodes, docs@python, gvanrossum, orsenthil, python-dev
Priority: normal Keywords: patch

Created on 2016-04-16 14:06 by brandon-rhodes, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pep8-knuth.patch brandon-rhodes, 2016-04-16 14:09
Messages (5)
msg263554 - (view) Author: Brandon Rhodes (brandon-rhodes) * Date: 2016-04-16 14:06
I am delighted to see that PEP-8 has pivoted to breaking long formulae before, rather than after, each binary operator! But I would like to pivot the PEP away from citing my own PyCon Canada talk as the authority on the matter, and toward citing Knuth himself. It would also be an enhancement for the PEP to show both options and make an argument for the practice, instead of simply asserting that one is better than the other. I therefore propose the attached patch.
msg263573 - (view) Author: Brandon Rhodes (brandon-rhodes) * Date: 2016-04-16 18:14
Another important objection against the current text is that it stacks a series of `and` and `or` operators at the same level of indentation, as though they naturally evaluate in the order the programmer writes them. In fact, they have different levels of precedence, and the code example violates the other sections of PEP-8 that ask for the creation of a visual distinction in code between different precedence levels.

The example needs to pivot towards a series of operators which belong at the same precedence level. I have used `+` and `-` because they seemed more natural to form an example from than something like division and multiplication.
msg263588 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2016-04-16 21:12
Patch LGTM.

Note that the and/or example was in the PEP before this discussion broke out.

The discussion also at some point (before your Knuth quote was discovered) veered in the direction of making and/or a special case, perhaps because it's more likely that a long expression must be broken around and/or operators. And there were already examples of breaking after binary arithmetic operators elsewhere in the PEP (I think).
msg263799 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-04-20 06:15
New changeset 9afe77ad549b by Senthil Kumaran in branch 'default':
PEP-8 Update on Knuth style breaking of a long formula. #issue26780
https://hg.python.org/peps/rev/9afe77ad549b
msg263800 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2016-04-20 06:17
The patch is committed in changeset 9afe77ad549b.

Thanks for update Brandon. Citing the original source and stating the rationale for this suggestion was a great addition.
History
Date User Action Args
2022-04-11 14:58:29adminsetgithub: 70967
2016-04-20 06:17:58orsenthilsetstatus: open -> closed

nosy: + orsenthil
messages: + msg263800

resolution: fixed
stage: resolved
2016-04-20 06:15:35python-devsetnosy: + python-dev
messages: + msg263799
2016-04-16 21:12:32gvanrossumsetmessages: + msg263588
2016-04-16 18:14:59brandon-rhodessettype: enhancement
2016-04-16 18:14:37brandon-rhodessetmessages: + msg263573
2016-04-16 14:09:11brandon-rhodessetfiles: + pep8-knuth.patch
2016-04-16 14:08:37brandon-rhodessetfiles: - pep8-knuth.patch
2016-04-16 14:06:44brandon-rhodescreate