<div dir="ltr"><div class="gmail_quote"><div dir="ltr">[Chris Barker]<br></div>> ...<br>> So what about: <br>><br>> l = [x:=i for i in range(3)]<br>><br>> vs<br>><br>> g = (x:=i for i in range(3))<br>><br>> Is there any way to keep these consistent if the "x" is in the regular local scope?<br><div><br>I'm not clear on what the question is.  The list comprehension would bind `<span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span> </span>l<span> ` to [0, 1, 2] and leave the local `x` bound to 2.  The second example binds `g` to a generator object, which just sits there unexecuted.  That has nothing to do with the PEP, though.<br><br>If you go on to do, e.g.,<br><br>l = list(g)<br><br>then, same as the listcomp, `l` will be bound to [0, 1, 2] and the local `x` will be left bound to 2.<br><br>The only real difference is in _when_ the `<span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">x:=i for i in range(3)` part gets executed.  There's no new twist here due to the PEP.  Put a body B in a listcomp and any side effects due to executing B happen right away, but put B in a genexp and they don't happen until you force the genexp to yield results.<br></span><br>For example, do you think these two are "consistent" today?<br><br>l = [print(i) for i in range(3)]</span></span></div><div><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span>g = (print(i) for i in range(3))<br><br>?  If so, nothing essential changes by replacing "print(i)" with "x := i" - in either case the side effects happen when the body is executed.<br><br>But if you don't think they're already consistent, then nothing gets less consistent either ;-)<br><br></span></span></div></div></div>