<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 7 May 2018 at 13:15, Tim Peters <span dir="ltr"><<a href="mailto:tim.peters@gmail.com" target="_blank">tim.peters@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">[Tim]<br>
<span class="">>> There's a difference, though: if `y` "leaks", BFD. Who cares? ;-)<br>
>> If `y` remains inaccessible, there's no way around that.<br>
</span><span class="">> Part of it is just that people seem to be fighting for the sake of<br>
> fighting. I'm weary of it, and I'm not going to debate this point with<br>
> you. You want 'em to leak? No problem. Implement it that way and I'm<br>
> not going to argue it.<br>
<br>
</span>I'm more interested in real-life use cases than in arguments. My<br>
suggestion came from staring at my real-life use cases, where binding<br>
expressions in comprehensions would clearly be more useful if the<br>
names bound leaked. Nearly (but not all) of the time,, they're quite<br>
happy with that for-target names don't leak. Those are matters of<br>
observation rather than of argument.<br></blockquote><div><br></div><div>The issue is that because name binding expressions are just ordinary expressions, they can't be defined as "in comprehension scope they do X, in other scopes they do Y" - they have to have consistent scoping semantics regardless of where they appear.<br><br></div><div>However, it occurs to me that a nonlocal declaration clause could be allowed in comprehension syntax, regardless of how any nested name bindings are spelt:<br><br> p = rem = None<br><div class="gmail_quote"><div class="gmail_quote"> while any((rem := n % p) for p in small_primes nonlocal (p, rem)):<br></div><div class="gmail_quote"> # p and rem were declared as nonlocal in the nested scope, so our rem and p point to the last bound value<br><br></div><div class="gmail_quote">I don't really like that though, since it doesn't read as nicely as being able to put the nonlocal declaration inline.<br></div></div><div class="gmail_quote"></div></div></div><br clear="all"></div><div class="gmail_extra">Cheers,<br></div><div class="gmail_extra">Nick.<br><br></div><div class="gmail_extra">-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Nick Coghlan | <a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a> | Brisbane, Australia</div>
</div></div>