[Python-3000] The meaning of "global variable"

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Sun Nov 5 22:46:18 CET 2006


Ron Adam <rrr at ronadam.com> writes:

> By not limiting parent to just the parent scope you create exceptions.  The rule 
> becomes:
>
>      The keyword (*)nonlocal designates a name will be written to in the
>      closest enclosing "parent" scope *except* when a pre-existing matching name
>      exists in a scope further up.
>
> To me that is more confusing than always referring to the closest enclosing 
> scope without exception.

The rule should be:

The keyword 'nonlocal' causes the lookup to be performed as if there
were no assignments to that variable in the scope containing the
'nonlocal' declaration.

No exceptions are needed, and no limitation to the immediately
surrounding scope is needed. Read accesses already have fine scoping
rules, as long as there is something to determine the scope. The only
problem with current rules is that assignment is coupled with creating
a new variable, and 'nonlocal' just allows to decouple that.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/


More information about the Python-3000 mailing list