[Python-ideas] 'Injecting' objects as function-local constants

Carl M. Johnson cmjohnson.mailinglist at gmail.com
Sat Jun 18 23:22:51 CEST 2011

On Sat, Jun 18, 2011 at 1:04 AM, Jacob Holm <jh at improva.dk> wrote:

> A consequence of this would be that you could optionally allow
> "nonlocal" to bind global names when there are no suitable nonlocal
> names to bind to (e.g. in a top-level function).  It has always slightly
> bothered me that you couldn't do that, because it makes it harder to
> move code between levels.

I will say that I was surprised to discover that `nonlocal` can be
used only for outer function locals and not for globals, since the
name "nonlocal" seems very general, as if it encompassed all things
not local. If it could be changed, I think it would be a little more
intuitive. In addition, as you mention, it's slightly better for

More information about the Python-ideas mailing list