PEP8 Recommendation E226

Error code E226 is the "space bar around the arithmetic operator".

I use the Anaconda package in Sublime, which highlights as a violation of PEP8 E226, for example, this line:

hypot2 = x*x + y*y 

But in the Guido PEP8 style guide this line is actually shown as an example, it is recommended to use spaces inside statements.

Question: what is the right guideline? Always spaces around operators, or only in some cases (as Guido's recommendation shows)?

Also: who decides what is included in PEP8? I would think that a Guido recommendation will pretty much determine how this works.

+6
source share
2 answers

The compilers of the PEP8 tool decide what happens in it.

As you noticed, they do not always correspond to the PEP8 style guide. In this particular case, I do not know how much this is accompanied by an accompanying, or deliberate decision. You must ask them to find out, or you can find the answer in the commit history.

Guido recently asked the accompanying tools pep8 and pep257 to rename them to avoid this confusion. See this problem for example . As a result, the tools are renamed to pycodestyle and pydocstyle, respectively.

+8
source

He says in PEP8:

If operators with different priorities are used, consider adding spaces around the operators with the lowest priority (s). Use your own opinion ; however, never use more than one space and should always have the same number of spaces on both sides of the binary operator. (Emphasis is my own).

In the example below, + has a lower priority, so the BDFL chooses to use spaces around it and does not use spaces with a higher priority * .

+5
source

All Articles