[Python-Dev] Using and binding relative names (was Re: PEP for Better Control of Nested Lexical Scopes)

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

On 2/23/06, Steven Bethard <steven.bethard at gmail.com> wrote:
> On 2/22/06, Almann T. Goo <almann.goo at gmail.com> wrote:
> >     def incrementer_getter(val):
> >        def incrementer():
> >            val = 5
> >            def inc():
> >                ..val += 1
> >                return val
> >            return inc
> >        return incrementer
> Sorry, what way did the user think?  I'm not sure what you think was
> supposed to happen.

My apologies ... I shouldn't use vague terms like what the "user
thinks."  My problem, as is demonstrated in the above example, is that
the implicit nature of evaluating a name in Python conflicts with the
explicit nature of the proposed "dot" notation.  It makes it easier
for a user to write obscure code (until Python 3K when we force users
to use "dot" notation for all enclosing scope access ;-) ).

This sort of thing can be done today with code using attribute access
on its module object to evaluate and rebind global names.  With the
"global" keyword however, users don't have to resort to this sort of

Because of Python's name binding semantics and the semantic for the
"global" keyword, I think the case for an "outer"-type keyword is
stronger and we could deprecate "global" going forward in Python 3K. 
One of the biggest points of contention to this is of course the
backwards incompatibility with a new keyword ... Python has already
recently added "yield" and we're about to get "with" and "as" in 2.5. 
As far as the "user-interface" of the language getting bloated, I
personally think trading "global" for an "outer" mitigates that some.


Almann T. Goo
almann.goo at gmail.com

More information about the Python-Dev mailing list