[Python-ideas] With clauses for generator expressions

Masklinn masklinn at masklinn.net
Thu Nov 15 13:20:49 CET 2012


On 2012-11-15, at 12:37 , Andrew Barnert wrote:
>> From: Masklinn <masklinn at masklinn.net>
>> Sent: Thu, November 15, 2012 2:25:47 AM
>> 
>> On 2012-11-15, at 11:08 , Andrew Barnert wrote:
>>> This is an  almost-unrelated side issue. A generator used in a single thread 
> 
>>> defines a fully deterministic dynamic scope
>> 
>> I think you meant "a context  manager" not "a generator"
> 
> No, I meant a generator. "As long as the generator has values to generate, and 
> has not been closed or destroyed" is a dynamic scope.

It isn't a dynamic scope in the sense of "dynamic scoping" which is the
one I used it in, and the one usually understood when talking about
dynamic scopes, which is a function of the stack context in which the
code executes not the lifecycle of an object.

> "Until the end of this with statement block" is a static scope.

Not from the POV of callees within the stack of which the with block is
part, which again is the standard interpretation for "dynamic scopes".

>> and my example
>> quite clearly demonstrates that  the interaction between context managers
>> and generators completely break  context managers as dynamic scopes.
> 
> No it doesn't. It demonstrates that it's possible to create indeterminate 
> scopes

There is nothing indeterminate about the scopes in a classical and usual
sense, neither the dynamic scope nor the lexical scope. And languages with
proper dynamic scoping support have no issue with this kind of constructs.

Neither does Python when walking through the whole stack, naturally.


More information about the Python-ideas mailing list