On 17/04/2018 15:01, Chris Angelico wrote:
On Tue, Apr 17, 2018 at 10:17 PM, Nick Coghlan <ncogh...@gmail.com> wrote:

Style guide recommendations
===========================

As this adds another way to spell some of the same effects as can already be
done, it is worth noting a few broad recommendations. These could be included
in PEP 8 and/or other style guides.

1. If either assignment statements or assignment expressions can be
    used, prefer statements; they are a clear declaration of intent.

2. If using assignment expressions would lead to ambiguity about
    execution order, restructure it to use statements instead.

3. Chaining multiple assignment expressions should generally be avoided.
    More than one assignment per expression can detract from readability.
Given the many different uses for ":" identified on python-ideas, I'm
inclined to suggest making these proposed style guidelines more
prescriptive (at least initially) by either:

1. Listing out specific approved unambiguous use cases (i.e. if
statement conditions, while loop conditions, list comprehensions,
generation expressions)
2. Making the 3rd admonition more general by advising against using
":" for more than one purpose in the same expression (i.e. don't
combine assignment expressions with slicing syntax, lambda
expressions, function headers, variable annotations, dict or set
displays, dict or set comprehensions)
I'm actually dubious about the third point as it stands.
I'm more than dubious - I disagree with Nick on this point.  It is already possible to have multiple uses of ":" in an expression; surely we wouldn't advise that such existing code should be changed, in cases where it is arises naturally and is genuinely useful.
Best wishes
Rob Cliffe
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to