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

Guido van Rossum guido at python.org
Wed Apr 26 01:23:18 CEST 2006


On 4/24/06, Aahz <aahz at pythoncraft.com> wrote:

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.

I strongly object to your use of the term "namespace" here. The with statement does not create a new namespace. Using the term namespace will only confuse people who understand what it means (in Python) -- we have the global namespace, the builtin namespace, the local namespace, classes introduce a new namespace, etc. The with-statement does not create a namespace in this sense -- there's no new place where name lookup can take place. In particular, this code prints 42:

x = 1 with whatever(doesnt_matter): x = 42 print x

-- --Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list