On 2/5/2021 2:51 AM, Paul Sokolovsky wrote:

https://www.python.org/dev/peps/pep-0572/
...

((a, b) := (1, 2))
   File "<stdin>", line 1
SyntaxError: cannot use assignment expressions with tuple
----

Why this accidental syntactic gap?

As should be clear from reading "Differences between assignment expressions and assignment statements", this 'gap' in entirely intentional, not accidental. *All* elaborations of 'name := expression' are listed and rejected as outside the scope of the proposal, which was to keep one reference to the expression value for later use. At least some of these elaborations were suggested and rejected during the voluminous discussion.

The principal a.e. use in conditional expressions is testing for non-nullness. Your

> while ((a1, b1) := phi([a0, a2], [b0, b2]))[0] < 5:
>    a2 = a1 + 1
>    b2 = b1 + 1

is an unusual and very specific use. You want to have your tuple (for subscripting for testing) and eat it too (by unpacking). One can instead separate unpacking from testing a couple of ways

while (tup := phi([a0, a2], [b0, b2]))[0] < 5:
    a2, b2 = tup
    a2 = a1 + 1
    b2 = b1 + 1


while True:
    a1, b1 = phi([a0, a2], [b0, b2])
    if a1 >= 5: break
    a2 = a1 + 1
    b2 = b1 + 1


--
Terry Jan Reedy
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/VM3OJ4E73DQXHNUB2JV67JALI2EEO3DP/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to