[Python-Dev] anonymous blocks

Josiah Carlson jcarlson at uci.edu
Wed Apr 20 00:21:27 CEST 2005

[Guido van Rossum]
> @EXPR:
>     CODE
> would become something like
> def __block():
>     CODE
> EXPR(__block)
> I'm not yet sure whether to love or hate it. :-)

Is it preferable for CODE to execute in its own namespace (the above
being a literal translation of the given code), or for it to execute in
the originally defined namespace?

Deferring to Greg Ewing for a moment [1]:
They should be lexically scoped, not dynamically scoped.

Wrapped blocks in an old namespace, I believe, is the way to go,
especially for things like...

    a = foo.method()

I cannot come up with any code for which CODE executing in its own
namespace makes sense.  Can anyone else?

<discussion on the overlap with PEP 310 removed for brevity>

 - Josiah

[1] http://mail.python.org/pipermail/python-dev/2005-March/052239.html

More information about the Python-Dev mailing list