[Python-Dev] PEP 343 update (with statement context terminology)

Aahz aahz at pythoncraft.com
Mon Apr 24 21:49:01 CEST 2006


On Mon, Apr 24, 2006, Phillip J. Eby wrote:
> At 12:24 PM 4/24/2006 -0700, Aahz wrote:
>>On Mon, Apr 24, 2006, Phillip J. Eby wrote:
>>> At 04:48 AM 4/25/2006 +1000, Nick Coghlan wrote:
>>>>
>>>>Using two names to describe three different things isn't intuitive for
>>>>anybody.
>>>
>>> Um, what three things?  I only count two:
>>>
>>> 1. Objects with __context__
>>> 2. Objects with __enter__ and __exit__
>>>
>>> What's the third thing?
>>
>>The actual context that's used during the execution of BLOCK.  It does
>>not exist as a concrete object,
> 
> Um, huh?  It's a thing but it's not an object?  I'm lost now.  I don't see 
> why we should introduce a concept that has no concrete existence into 
> something that's hard enough to explain when you stick to the objects that 
> actually exist.  :)

Let's go back to a pseudo-coded with statement:

    with EXPRESSION [as NAME]:
        BLOCK

What happens while BLOCK is being executed?  Again, here's what I said
originally:

    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.

Do you have an alternate proposal for describing this that works well for
newbies?  Forget about the internal mechanics of what really happens, we
must have a simple way of describing the with block itself!
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Argue for your limitations, and sure enough they're yours."  --Richard Bach


More information about the Python-Dev mailing list