[Python-Dev] Suggested addition to PEP 8 for context managers

Eli Bendersky eliben at gmail.com
Thu Apr 19 05:06:35 CEST 2012


>>> Quoting from
>>> http://www.python.org/dev/peps/pep-0008/#other-recommendations
>>> (with elision):
>>>
>>> Use spaces around arithmetic operators:
>>>    No:
>>>       i=i+1
>>>       submitted +=1
>>>       x = x*2 - 1
>>>       hypot2 = x*x + y*y
>>>       c = (a+b) * (a-b)
>>>
>>> End quote.
>>
>>
>> I agree that this could be reworded.  Especially when the operands are
>> as short as in the examples, the last three "No"s read better to me than
>> the "Yes" entries.  In this case, spacing serves for visually grouping
>> expressions by precedence, which otherwise could also be indicated by
>> (semantically unnecessary) parens.
>
> Indeed. I don't know who put that in, it wasn't me.
>
>> But in all cases discussed here, PEP8 should not be seen as a law.
>> Its second section ("A Foolish Consistency is the Hobgoblin of Little
>> Minds") is quite prominent for a reason.
>
> I think whoever put that blanket rule in the PEP fell prey to this.
>
> Let's change this to something more reasonable, e.g.
>
> """
> If operators with different priorities are used, consider adding
> whitespace around the operators with the lowest priority(ies). This is
> very much to taste, however, never use more than one space, and always
> have the same amount of whitespace on both sides of a binary operator.
> """

+1, a very welcome change to a piece of PEP8 I've always felt
uncomfortable with. Tiny nitpick: I'd just replace the comma following
"however" with a period or semicolon.

Eli


More information about the Python-Dev mailing list