[Python-Dev] PEP for Better Control of Nested Lexical Scopes

Almann T. Goo almann.goo at gmail.com
Sun Feb 26 08:07:32 CET 2006

On 2/22/06, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> That's what rankles people about this, I think -- there
> doesn't seem to be a good reason for treating the global
> scope so specially, given that all scopes could be
> treated uniformly if only there were an 'outer' statement.
> All the arguments I've seen in favour of the status quo
> seem like rationalisations after the fact.

I agree, hence my initial pre-PEP feeler on the topic ;).

> > Since there were no nested lexical scopes back
> > then, there was no need to have a construct for arbitrary enclosing
> > scopes.
> However, if nested scopes *had* existed back then, I
> rather suspect we would have had an 'outer' statement
> from the beginning, or else 'global' would have been
> given the semantics we are now considering for 'outer'.

Would it not be so horrible to make "global" be the "outer"-type
keyword--basically meaning "lexically global" versus "the global
scope"?  It would make the semantics for Python's nested lexical
scopes to be more in line with other languages with this feature and
fix my orthogonality gripes.  As far as backwards compatibility, I
doubt there would be too much impact in this regard, as places that
would break would be where "global" was used in a closure where the
name was shadowed in an enclosing scope.  A "from __future__ import
lexical_global" (which we'd have for adding the "outer"-like keyword
anyway) could help diminish the growing pains.


Almann T. Goo
almann.goo at gmail.com

More information about the Python-Dev mailing list