PEP 227 (was Re: Nested scopes resolution -- you can breathe again!)

Joshua Marshall jmarshal at mathworks.com
Thu Mar 1 12:44:26 EST 2001


Alex Martelli <aleaxit at yahoo.com> wrote:
> "Jeremy Hylton" <jeremy at alum.mit.edu> wrote in message
> news:mailman.983384008.21434.python-list at python.org...
>     [snip]
>>   Rebinding names in enclosing scopes
>     [snip]
>>       opposed to it.  It is difficult to support, because it would
>>       require a new mechanism that would allow the programmer to specify
>>       that an assignment in a block is supposed to rebind the name in an
>>       enclosing block; presumably a keyword or special syntax (x := 3)
>>       would make this possible.

> If this were to be allowed (and I'm not saying it should be!), the
> most natural way to allow it would appear to be to be a new clause
> on the global statement -- most natural, because "allow rebinding
> in an outer scope" is exactly global's job (of course, up to Python
> 2, the only 'outer scope' was the module-one:-).

> Maybe something like...:

>     def spam():
>         def inner():
>             global in spam, x
>             x += 1
>         x = 23
>         inner()

Or how about just using "global" as is?  If you declare a variable
reference global, then search the enclosing scopes until you find the
right name.  It will break a little code, but on the same order as
this incompatible change will already break.



More information about the Python-list mailing list