[Python-Dev] statically nested scopes

M.-A. Lemburg mal@lemburg.com
Thu, 02 Nov 2000 18:07:15 +0100

Guido van Rossum wrote:
> > It may not look serious, but changing the Python lookup scheme
> > is, since many inspection tools rely and reimplement exactly
> > that scheme. With nested scopes, there would be next to no
> > way to emulate the lookups using these tools.
> So fix the tools.

Eek. Are you proposing to break all the Python IDE that are
just appearing out there ?

> > To be honest, I don't think static nested scopes buy us all that
> > much. You can do the same now, by using keyword arguments which
> > isn't all that nice, but works great and makes the scope clearly
> > visible.
> Yes.  It's a hack that gets employed over and over.  And it has
> certain problems.  We added 'import as' to get rid of a common
> practice that was perceived unclean.  Maybe we should support nested
> scopes to get rid of another unclean common practice?

I think the common practice mainly comes from the fact,
that by making globals locals which can benefit from LOAD_FAST
you get a noticable performance boost.

So the "right" solution to these weird looking hacks would
be to come up with a smart way by which the Python compiler
itself can do the localizing.

Nested scopes won't help eliminating the current keyword 
> I'm not saying that we definitely should add this to 2.1 (there's
> enough on our plate already) but we should at least consider it, and
> now that we have cycle GC, the major argument against it (that it
> causes cycles) is gone...

Hmm, so far the only argument for changing Python lookups
was to allow writing lambdas without keyword hacks. Does this
really warrant breaking code ?

What other advantages would statically nested scopes have ?

Marc-Andre Lemburg
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/