[Python-Dev] PEP 572: Assignment Expressions
Rob Cliffe
rob.cliffe at btinternet.com
Tue Apr 17 19:34:30 EDT 2018
More information about the Python-Dev mailing list
Tue Apr 17 19:34:30 EDT 2018
- Previous message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Next message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 17/04/2018 15:01, Chris Angelico wrote: > On Tue, Apr 17, 2018 at 10:17 PM, Nick Coghlan <ncoghlan at 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
- Previous message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Next message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list