[Python-Dev] PEP 572: Assignment Expressions
Guido van Rossum
guido at python.org
Fri Apr 20 17:28:02 EDT 2018
On Fri, Apr 20, 2018 at 2:04 PM, Chris Angelico <rosuav at gmail.com> wrote:
> On Sat, Apr 21, 2018 at 6:59 AM, Guido van Rossum <guido at python.org>
> wrote:
> > Does the PEP currently propose to *allow* that horrible example? I
> thought
> > Tim Peters successfully pleaded to *only* allow a single "NAME :=
> <expr>".
> > You don't have to implement this restriction -- we know it's possible to
> > implement, and if specifying this alone were to pull enough people from
> -1
> > to +0 there's a lot of hope!
>
> I don't see much value in restricting the assignment target to names
> only, but if that's what it takes, it can be restricted, at least
> initially.
All of this is an exercise in listening and compromise, not in solving
puzzles.
> As to chaining... well, since the entire construct (target
> := expr) is an expression, it can be used on the right of :=, so short
> of outright forbidding it, there's not a lot to be done.
>
It would be more work but it can definitely be done (perhaps by introducing
a syntactic construct of intermediate precedence). People could write "a :=
(b := foo())" but that way they resolve the ambiguity. Although if we
restrict targets to just names there's less concern about ambiguity.
--
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180420/19320e93/attachment-0001.html>
More information about the Python-Dev
mailing list