<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2018-04-15 15:21 GMT+03:00 Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On Sun, Apr 15, 2018 at 7:19 PM, Kirill Balunov <<a href="mailto:kirillbalunov@gmail.com">kirillbalunov@gmail.com</a>> wrote:<br>
>> === Expression first, 'as' keyword ===<br>
>><br>
>>     while (read_next_item() as value) is not None:<br>
>>         ...<br>
>><br>
>> Pros:<br>
>><br>
>>   * typically reads nicely as pseudocode<br>
>>   * "as" is already associated with namebinding operations<br>
>><br>
><br>
> I understand that this list is subjective. But as for me it will be huge PRO<br>
> that the expression comes first.<br>
<br>
</span>I don't think we're ever going to unify everyone on an arbitrary<br>
question of "expression first" or "name first". But to all the<br>
"expression first" people, a question: what if the target is not just<br>
a simple name?<br>
<br>
while (read_next_item() -> items[i + 1 -> i]) is not None:<br>
    print("%d/%d..." % (i, len(items)), end="\r")<br>
<br>[...]<br>
<br>
Not a rhetorical question. I'm genuinely curious as to whether people<br>
are expecting "expression -> NAME" or "expression -> TARGET", where<br>
TARGET can be any valid assignment target.<br><div class="gmail-HOEnZb"><div class="gmail-h5"><br>
</div></div></blockquote></div><br></div><div class="gmail_extra">I completely agree with you that it is impossible to unify everyone opinion - we all have different background. But this example is more likely to play against this PEP. This is an extra complexity within one line and it can fail hard in at least three obvious places :) And I am against this usage no matter `name first` or `expression first`. But i will reask this with following snippets. What do you choose from this examples:</div><div class="gmail_extra"><br></div><div class="gmail_extra">0. </div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_extra"><font face="monospace, monospace">while (items[i := i+1] := read_next_item()) is not None:</font></div></div><div class="gmail_extra"><div class="gmail_extra"><font face="monospace, monospace">    print(r'%d/%d' % (i, len(items)), end='\r')</font></div><div class="gmail_extra"><br></div></div></blockquote>1.<div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><font face="monospace, monospace">while (read_next_item() -> items[(i+1) -> i]) is not None:</font></div><div><font face="monospace, monospace">    print(r'%d/%d' % (i, len(items)), end='\r')</font></div></div></blockquote></div><div>2.</div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><font face="monospace, monospace">while (item := read_next_item()) is not None:</font></div><div><font face="monospace, monospace">    items[i := (i+1)] = item</font></div><div><font face="monospace, monospace">    print(r'%d/%d' % (i, len(items)), end='\r')</font></div></div></blockquote></div><div>3.</div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><font face="monospace, monospace">while (read_next_item() -> item) is not None:</font></div><div><font face="monospace, monospace">    items[(i+1) -> i] = item</font></div><div><font face="monospace, monospace">    print(r'%d/%d' % (i, len(items)), end='\r')</font></div></div></blockquote></div><div>4.</div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><font face="monospace, monospace">while (item := read_next_item()) is not None:</font></div><div><font face="monospace, monospace">    i = i+1</font></div><div><font face="monospace, monospace">    items[i] = item</font></div><div><font face="monospace, monospace">    print(r'%d/%d' % (i, len(items)), end='\r')</font></div></div></blockquote></div><div>5. </div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><font face="monospace, monospace">while (read_next_item() -> item) is not None:</font></div></div><div><div><font face="monospace, monospace">    i = i+1</font></div></div><div><div><font face="monospace, monospace">    items[i] = item</font></div></div><div><div><font face="monospace, monospace">    print(r'%d/%d' % (i, len(items)), end='\r')</font></div></div><div><br></div></blockquote>I am definitely Ok with both 2 and 3 here. But as it was noted `:=` produces additional noise in other places and I am also an `expression first` guy :) So I still prefer variant 3 to 2. But to be completely honest, I would write it in the following way:<div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div><font face="monospace, monospace">for item in iter(read_next_item, None):</font></div></div><div><div><font face="monospace, monospace">    items.append(item)</font></div></div><div><div><font face="monospace, monospace">    print(r'%d/%d' % (i, len(items)), end='\r')</font></div></div></blockquote><div><br></div><div>With kind regards,</div><div>-gdg</div></div>