<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2018-04-26 13:20 GMT+03:00 Steve Holden <span dir="ltr"><<a href="mailto:steve@holdenweb.com" target="_blank">steve@holdenweb.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"><div dir="ltr"><span class="gmail-"><div style="font-size:small">On Thu, Apr 26, 2018 at 8:56 AM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>></span> wrote:<br></div></span><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>On Thu, Apr 26, 2018 at 03:31:13AM -0400, Terry Reedy wrote:<br>
> On 4/25/2018 8:20 PM, Chris Angelico wrote:<br>
> >On Thu, Apr 26, 2018 at 10:11 AM, Yury Selivanov<br>
> ><<a href="mailto:yselivanov.ml@gmail.com" target="_blank">yselivanov.ml@gmail.com</a>> wrote:<br>
> >>Just yesterday this snippet was used on python-dev to show how great the<br>
> >>new syntax is:<br>
> >><br>
> >> my_func(arg, buffer=(buf := [None]*get_size()), size=len(buf))<br>
> <br>
> What strikes me as awful about this example is that len(buf) is <br>
> get_size(), so the wrong value is being named and saved. <br>
> 'size=len(buf)' is, in a sense, backwards.<br>
<br>
</span>Terry is absolutely right, and I'm to blame for that atrocity. Mea <br>
culpa.<br>
<br></blockquote></span><div><div style="font-size:small;display:inline">Perhaps a better spelling would be</div></div><div><div style="font-size:small;display:inline"><br></div></div><div><div style="font-size:small;display:inline"> my_func(arg, buffer=[None]*(buflen := get_size()), size=buflen)</div></div><div><br></div></div></div></div></blockquote></div><br></div><div class="gmail_extra"><div class="gmail_extra">I know it is non productive and spamy (I promise, this is the last) since `as` syntax is dead. In many cases, there is not much difference in perception between `:=` and `as`. But in several situations, like this one and as Ethan pointed up-thread - the expression first syntax makes obvious the intent and linearly readable:</div><div class="gmail_extra"><br></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_extra"><font face="monospace, monospace">my_func(arg, buffer=[None]*get_size() as buf, size=buf) </font></div></div></blockquote><div class="gmail_extra"><div class="gmail_extra"><br></div><div class="gmail_extra">In any case, it is rather an anti-pattern than a good example to follow.</div><div class="gmail_extra"><br></div><div class="gmail_extra">p.s.: as Victor Stinner wrote on twitter that previously, there was a similar PEP in spirit - "PEP 379 -- Adding an Assignment Expression", which was withdrawn. May be it is worth to make a link to it in the current PEP.</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">With kind regards, </div><div class="gmail_extra">-gdg</div></div></div>