[Python-Dev] Lexical scoping in Python 3k

Almann T. Goo almann.goo at gmail.com
Sat Jul 1 18:42:27 CEST 2006

On 7/1/06, Josiah Carlson <jcarlson at uci.edu> wrote:

> > There's one very simple way we could do this in Py3k
> > without requiring any new syntax or keywords: just
> > redefine the meaning of "global" to mean "not local".
> I would probably be a solid -0 on such a proposal; I still don't think
> it's really necessary, but I've never used (or really seen) global more
> than one level deep, so would guess its impact would be low.

This has been discussed at length in the following thread that I started in
February and at least one time before that.


I think using the "global" keyword is probably the lowest impact form and
has the least amount of backwards incompatibility.  Below is the part of the
last thread that I talked about changing the meaning of "global."


Having the "global" keyword semantics changed to be "lexically global"
would break in the cases that "global" is used on a name within a
nested scope that has an enclosing scope with the same name.  I would
suppose that actual instances in real code of this would be rare.

>>>* x = 1
*>>>* def f() :
*...   x = 2
...   def inner() :
...     global x
...     print x
...   inner()
>>>* f()

Under the proposed rules:
>>>* f()

PEP 227 also had backwards incompatibilities that were similar and I
suggest handling them the same way by issuing a warning in these cases
when the new semantics are not being used (i.e. no "from __future__").

Most people probably think that this is a low impact "wart" on the Python
language that not really worth fixing as there are workarounds (i.e. mutable
objects) or other ways to express (i.e. use classes) such things, but it
does trip people up from time to time as warts typically do--I guess that's
why this gets brought up now and again.

Best regards,

Almann T. Goo
almann.goo at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20060701/7f3f113c/attachment.html 

More information about the Python-Dev mailing list