[Python-Dev] With context, please

Phillip J. Eby pje at telecommunity.com
Sat Apr 22 18:38:13 CEST 2006


At 09:25 AM 4/22/2006 -0700, Aahz wrote:
> EXPRESSION returns a value that the with statement uses to create a
> context (a special kind of namespace). The context is used to
> execute the BLOCK. The block might end normally, get terminated by
> a break or return, or raise an exception. No matter which of those
> things happens, the context contains code to clean up after the
> block.
>> The as NAME part is optional. If you include it, you can use NAME
> in your BLOCK
>>Then a bit later:
>> The protocol used by the with statement is called the context
> management protocol, and objects implementing it are context
> managers.

Okay, which means that you agree with AMK and Paul Moore that the thing you 
pass to "with" is a context manager, and the thing that controls execution 
is a context. Was that conclusion independently arrived at, or based on 
reading e.g. the docs I wrote? Obviously, if you guys came up with that 
terminology on your own, that's a stronger vote in its favor.
Btw, the phrase "special kind of namespace" seems wrong to me, since there 
are no names in a context, and that phrase makes it sound like you get a 
new scope. Looks to me like you could replace the word "namespace" with 
"object" without changing the intended effect. (That is, I assume the 
intended effect was merely to point out you're introducing a new term that 
the reader is not yet expected to know.)


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /