[Python-Dev] nonlocal keyword in 2.x?

Fabio Zadrozny fabiofz at gmail.com
Thu Oct 22 17:32:37 CEST 2009

On Wed, Oct 21, 2009 at 10:56 PM, Mike Krell <mbk.lists at gmail.com> wrote:
> Is there any possibility of backporting support for the nonlocal keyword
> into a  2.x release?  I see it's not in 2.6, but I don't know if that was an
> intentional design choice or due to a lack of demand / round tuits.  I'm
> also not sure if this would fall under the scope of the proposed moratorium
> on new language features (although my first impression was that it could be
> allowed since it already exists in python 3.
> One of my motivations for asking is a recent blog post by Fernando Perez of
> IPython fame that describes an interesting decorator-based idiom inspired by
> Apple's Grand Central Dispatch which would allow many interesting
> possibilities for expressing parallelization and other manipulations of
> execution context for blocks of python code.  Unfortunately, using the
> technique to its fullest extent requires the nonlocal keyword.
> The blog post is here:
> https://cirl.berkeley.edu/fperez/py4science/decorators.html

Just as a note, the nonlocal there is not a requirement...

You can just create a mutable object there and change that object (so,
you don't need to actually rebind the object in the outer scope).

E.g.: instead of creating a float in the context, create a list with a
single float and change the float in the list (maybe the nonlocal
would be nicer, but it's certainly still usable)



More information about the Python-Dev mailing list