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

Georg Brandl g.brandl at gmx.net
Wed Apr 18 18:25:16 CEST 2012


On 18.04.2012 17:47, Chris Angelico wrote:
> On Thu, Apr 19, 2012 at 12:47 AM, Guido van Rossum<guido at python.org>  wrote:
>>  I don't believe PEP 8 requires whitespace around all binary operators.
>>  Where do you read that?
>
> 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.

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.

Georg



More information about the Python-Dev mailing list