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

Terry Reedy tjreedy at udel.edu
Sun Jun 19 07:09:20 CEST 2011

On 6/18/2011 5:22 PM, Carl M. Johnson wrote:

> 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.

We were aware of that when it was selected, after much discussion.
Closures were originally read-only partly because it was uncertain how 
to spell 'write'.

> If it could be changed, I think it would be a little more
> intuitive.

It cannot, I hope for obvious reasons.

I should hope that the docs make clear enought that names in a function 
are *partitioned* into module, closure, and local and that written names 
are local by default or one of the other 2 if declared.

Actually, I think improving the nonlocal doc is part of some issue.

Terry Jan Reedy

More information about the Python-ideas mailing list