<div dir="ltr"><div class="gmail_quote"><div dir="ltr">[Ivan Pozdeev]</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Victor Stinner in "Assignment expression and coding style: the while <br>
True case" and others have brought to attention<br>
<br>
that the AE as currently written doesn't support all the capabilities of <br>
the assignment statement, namely:<br>
<br>
* tuple unpacking<br>
* augmented assignment<br>
<br>
(I titled the letter "all capabilities" 'cuz I may've missed something.)<br>
<br></blockquote><div>Assignment statements (and `for` headers) also allow arbitrarily complex applications of subscripting and attribute references. Like<br><br> for a[b].cde[f, g(h, i, j)].k in range(10):<br><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Should it?<br></blockquote><div><br>Already been considered and rejected, so no.</div><div><br></div><div>Victor already showed why, but didn't quite realize it ;-)<br><br>while True:</div><div> name, token = _getname(g)</div><div> if not name:</div><div> break</div><div><br></div><div>Allowing to unpack the two names in an AE wouldn't really help, because there's still no satisfying way then to _reference_ just the `name` part in the `while` test:<br><br> while ((name, token) := _getname(g)) ... and now what??<br><br>You could use "a trick", relying on that a 2-tuple is always truthy:<br><br>
<span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> while ((name, token) := _getname(g)) and name:<br></span><br>Using a trick sucks. Not relying on a trick is ugly and inefficient:<br><br>
<span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> while [((name, token) := _getname(g)), name][-1]:</span><br>or<br><span style="text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255);float:none;display:inline"> while [((name, token) := _getname(g)), name].pop():</span><br style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> <br></span>where the thing to be tested is the second list element (e.g., `name == "not done yet"`).<br><br>So no plausible use cases were ever presented, and the idea was dropped.<br><br>If we _also_ added something akin to C's comma expressions (evaluate a sequence of expressions and throw away all the results except for the last), then a reasonable spelling akin to the last one above could be used, but without the strained cruft to muck with a result list (or tuple).</div><div><br></div><div>At which point my rule for AE would likely never trigger ("if it's not obviously better, don't use it").<br><br><br></div></div></div>