Hi James

Thank you for your message. I have some general, background comments.
However, the question remains: Does your proposal sit well with the
rest of Python?

By the way, I've just found a nice article:
http://treyhunner.com/2018/03/tuple-unpacking-improves-python-code-readability/

You wrote

> Currently, is <expr1> = <expr2> = <expr3> = <expr4> always equivalent
> to <expr1> = <expr4>; <expr2> = <expr4>; <expr3> = <expr4>?

It is very important, in this context, to know what we can assign to.
We can assign to some expressions, but not others. Here are some
examples

>>> fn() = 4
SyntaxError: can't assign to function call
>>> fn()[0] = 4
NameError: name 'fn' is not defined
>>> 1 = 2
SyntaxError: can't assign to literal
>>> None = None
SyntaxError: can't assign to keyword

When assigned to, the expression "(a, b)" has a special meaning.
Strictly speaking, we are not assigning to a tuple. Hence

>>> (fn()[1], a.b) = (0, 1)   # Valid syntax.
NameError: name 'fn' is not defined

Finally, here's something that surprised me a little bit

>>> x = [1, 2]; id(x)
140161160364616
>>> x += [3, 4]; id(x)
140161160364616

>>> x = (1, 2); id(x)
140161159928520
>>> x += (3, 4); id(x)
140161225906440

Notice that '+=' creates uses the same object when the object is a
list, but creates a new object. This raises the question: Why and how
does Python behave in this way?

Finally, thank you for your stimulating idea. I think to take it
forward you have to deal with two questions:

1. Does the proposal sit well with the rest of Python?
2. Does it IN PRACTICE bring sufficient benefits to users?

Please note that Python deservedly has a reputation for being a
readable language. Some will argue that allowing
>>> (a, b) += (c, d)
may bring benefits to the author of the line of code, but to the cost
of the line of code.

Somewhere, as I recall, I read that writing
   a = <EXP1>
   b = <EXP2>
is preferable for reasons of clarity to
    a, b = <EXP1>, <EXP2>
when the two assignments are unrelated.

-- 
Jonathan
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to