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

Steven D'Aprano steve at pearwood.info
Thu Apr 19 02:16:05 CEST 2012


Hrvoje Niksic wrote:

> The same oddity occurs with expressions in kwargs calls:
> 
> func(pos1, pos2, keyword=foo + bar)
> 
> I find myself wanting to add parentheses arround the + to make the code 
> clearer.

Then why don't you?

In the above example, spaces around the + are not only optional but 
discouraged, this would be preferred:

func(pos1, pos2, keyword=foo+bar)

but if you insist on using spaces (perhaps because it is part of a larger 
expression) just use parentheses.

func(pos1, pos2, keyword=(foo*spam*ham*eggs + bar/spam**cheese))


Strictly speaking they're not needed, but if they make it easier to read (and 
I think they do) then why would you not use them?



-- 
Steven


More information about the Python-Dev mailing list