<div dir="ltr"><div class="gmail_quote"><div>Let me be slightly contrarian. :-)<br></div><div dir="ltr"><br></div><div dir="ltr">On Wed, Jul 4, 2018 at 9:12 PM Chris Angelico <<a href="mailto:rosuav@gmail.com">rosuav@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Definitely against augmentation, for several reasons:<br>
<br>
1) Spelling - should it be :+= or +:= ?<br></blockquote><div><br></div><div>That one's easy. As Nick's (withdrawn) PEP 577 shows it should be simply `+=`.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2) Is the result of the expression the modified value or the original?<br></blockquote><div><br></div><div>Someone (sadly I forget who) showed, convincingly (to me anyways :-) that it should return whatever the `__iadd__` method returns, or (if there isn't one) the result of `a = a + b`.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
3) The use-cases simply aren't as strong.<br></blockquote><div><br></div><div>Here I agree.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Supporting arbitrary assignment targets (rather than just a simple<br>
name) could be useful, but can be deferred to a future enhancement<br>
without impacting the simpler version. I would divide this up into two<br>
subgroups:<br>
<br>
* Multiple assignment (sequence unpacking)<br></blockquote><div><br></div><div>Tim Peters showed in his response this isn't all that helpful. I also think we shouldn't open the can of worms about priorities this presents, e.g. is (a, b := foo()) equivalent to ((a, b) := foo()) or is it like (a, (b := foo()))?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
* Assignment to non-simple names eg "x[1] := expr"<br>
<br>
Assigning directly to an item or attribute could in theory be<br>
immensely valuable. So could multiple assignment, though I suspect to<br>
a lesser extent. But tell me: Without looking it up, do you know which<br>
of these constructs support non-simple-name assignment and which<br>
don't?<br>
<br>
[x[1] for x[1] in seq]<br>
with ctx() as x[1]:<br>
except Exception as x[1]:<br>
from spam import ham as x[1]<br>
<br>
In the enormous majority of cases, every one of these constructs is<br>
going to be used with a simple name, even though some (I won't say how<br>
many) do permit you to do what I did here. If Python 3.8 ships with<br>
assignment expressions restricted to simple names, we can discuss how<br>
valuable the other forms of assignment target would be, and then<br>
figure out what to do about the ambiguities - for instance, is "x, y<br>
:= expr" going to be equivalent to "x, (y := expr)" or "(x, y) :=<br>
expr" ? As it is, we neatly dodge that.<br></blockquote><div><br></div><div>Again, the biggest argument against this is that there just aren't enough use cases. <br></div></div><br>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)</div></div>