<br><br>On Friday, April 27, 2018, Chris Angelico <<a href="mailto:rosuav@gmail.com">rosuav@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, Apr 27, 2018 at 8:18 PM, Wes Turner <<a href="mailto:wes.turner@gmail.com">wes.turner@gmail.com</a>> wrote:<br>
> IDK, I could just be resistant to change, but this seems like something that<br>
> will decrease readability -- and slow down code review -- without any real<br>
> performance gain. So, while this would be useful for golfed-down (!)<br>
> one-liners with pyline,<br>
> I'm -1 on PEP 572.<br>
<br>
PEP 572 has never promised a performance gain, so "without any real<br>
performance gain" is hardly a criticism.<br>
<br>
> How do I step through this simple example with a debugger?<br>
><br>
>     if re.search(pat, text) as match:<br>
>         print("Found:", match.group(0))<br>
<br>
Step the 'if' statement. It will call re.search() and stash the result<br>
in 'match'. Then the cursor would be put either on the 'print' (if the<br>
RE matched) or on the next executable line (if it didn't).</blockquote><div><br></div><div>Right. Pdb doesn't step through the AST branches of a line, so ternary expressions and list comprehensions and defining variables at the end of the line are 'debugged' after they're done.</div><div><br></div><div>Similarly, code coverage is line-based; so those expressions may appear to be covered but are not.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
> From <a href="https://en.wikipedia.org/wiki/Assignment_(computer_science)" target="_blank">https://en.wikipedia.org/wiki/<wbr>Assignment_(computer_science)</a> :<br>
><br>
>> In some languages the symbol used is regarded as an operator (meaning that<br>
>> the assignment has a value) while others define the assignment as a<br>
>> statement (meaning that it cannot be used in an expression).<br>
><br>
><br>
> PEP 572 -- Assignment Expressions<br>
> PEP 572 -- Assignment Operator (:=) and Assignment Expressions<br>
<br>
Huh? I don't get your point.</blockquote><div><br></div><div>Q: What is ':='? (How do I searchengine for it?)</div><div>A: That's the assignment operator which only works in Python 3.8+.</div><div><br></div><div>Q: When are variables defined -- or mutable names bound -- at the end of the expression accessible to the left of where they're defined?</div><div>Q: What about tuple unpacking? Is there an ECMAscript-like destructuring PEP yet?</div><div>A: Ternary expressions; list, dict, generator comprehensions; </div><div>(@DOCS PLEASE HELP EXPLAIN THIS)</div><div><br></div><div>Q: do these examples of the assignment expression operator all work?</div><div><br></div><div>"""</div><div><div style="color:rgb(34,34,34);font-size:14px">- debuggers have no idea what to do with all of this on one line</div><div style="color:rgb(34,34,34);font-size:14px">- left-to-right doesn't apply to comprehensions</div><div style="color:rgb(34,34,34);font-size:14px"><br></div><div style="color:rgb(34,34,34);font-size:14px">  results = [(x, y, x/y) for x in input_data if (y := f(x)) > 0]</div><div style="color:rgb(34,34,34);font-size:14px"><br></div><div style="color:rgb(34,34,34);font-size:14px">- left-to-right doesn't apply to ternary expressions<br></div><div style="color:rgb(34,34,34);font-size:14px"><br></div><div style="color:rgb(34,34,34);font-size:14px">  if (y := func(x)) if (x := 3) else 0:<br></div><div style="color:rgb(34,34,34);font-size:14px">  while (y := func(x)) if (x := 3) else 0:<br></div><div style="color:rgb(34,34,34);font-size:14px"><br></div><div style="color:rgb(34,34,34);font-size:14px">- left-to-right does apply to everything else?</div><div style="color:rgb(34,34,34);font-size:14px"><br></div><div style="color:rgb(34,34,34);font-size:14px">- *these* are discouraged:</div><div style="color:rgb(34,34,34);font-size:14px"><br></div><div style="color:rgb(34,34,34);font-size:14px">  if (x := 3) or (y := func(x)):</div><div style="color:rgb(34,34,34);font-size:14px">  if (3) or (func(3)):</div><div style="color:rgb(34,34,34);font-size:14px"><br></div><div style="color:rgb(34,34,34);font-size:14px">  if ((x := 3) if 1 else (y := func(x))):</div></div><div>"""</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
ChrisA<br>
______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/wes.turner%40gmail.com" target="_blank">https://mail.python.org/<wbr>mailman/options/python-dev/<wbr>wes.turner%40gmail.com</a><br>
</blockquote>