Re: [Python-Dev] assignment expressions: an alternative proposal

2018年4月24日 08:34:23 -0700

On 25 April 2018 at 00:54, Eric Snow <[email protected]> wrote:
> Regardless, your 3 rules would benefit either syntax. Nick may have a
> point that the rules might be an excessive burden, but I don't think
> it's too big a deal since the restrictions are few (and align with the
> most likely usage) and are limited to syntax so the compiler will be
> quick to point mistakes.
I think the "single name target only" rule should be in place no
matter the syntax for the name binding operator itself.
I don't mind too much either way on the mandatory parentheses question
(it's certainly an easy option to actively discourage use of binding
expressions as a direct alternative to assignment statements, but as
with the single-name-only rule, it's independent of the choice of
syntax)
I *do* think the "no name rebinding except in a while loop header"
restriction would be annoying for the if/elif use case and the while
use case:
 while (item = get_item()) is not first_delimiter:
 # First processing loop
 while (item = get_item()) is not second_delimiter:
 # Second processing loop
 # etc...
 if (target = get_first_candidate()) is not None:
 ...
 elif (target = get_second_candidate()) is not None:
 ...
 elif (target = get_third_candidate()) is not None:
 ...
And *that* rule is unique to the "=" spelling, since for other
proposals "lhs = rhs" in an expression is *always* a syntax error, and
you have to resolve the ambiguity in intent explicitly by either
adding a second "=" (to request equality comparison), or else some
other leading symbol (to request a binding expression).
Cheers,
Nick.
-- 
Nick Coghlan | [email protected] | Brisbane, Australia
_______________________________________________
Python-Dev mailing list
[email protected]
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