BTW, you can't use locals() or globals() because you really want globals()-overridden-with-locals(), i.e.
d = globals().copy() d.update(locals())
What about free/cell vars? Will these be used? If not, is that a problem?
Without compiler support for this construct we have no hope of getting references to outer non-global scopes right. E.g.
def f(): x = 12
def g(): return "x is $x".sub()
Here the compiler has no clue that g references x, so it wouldn't do the special treatment for x that's needed to make it work.
I see no way to fix this in general without introducing new syntax; note that the string "x is $x" could have been an argument to g().
--Guido van Rossum (home page: http://www.python.org/%7Eguido/)