[Python-Dev] 2.5 and beyond (original) (raw)

Guido van Rossum guido at python.org
Sat Jul 1 01:44:02 CEST 2006


On 6/30/06, Andrew Koenig <ark at acm.org> wrote:

> I read "a la Scheme" here as "actually nothing like Scheme, except I > want a non-tricky way to rebind a name from an enclosing scope within > an enclosed scope".

Almost. What I really want is for it to be possible to determine the binding of every name by inspecting the source text of the program. Right now, it is often possible to do so, but sometimes it isn't.

Then your example

def f(): return x x = 42 print f()

is entirely well-defined -- x is a global and the compiler in fact generates code that benefits from knowing that it's not a local.

Python knows which locals there are; also which locals there are in surrounding function scopes.

It could also know which globals and builtins there are, except the language currently allows dynamic rebinding of module-level variables so that they replace builtins.

E.g.

def f(): return len([]) print f() # prints 0 def len(x): return "booh" print f() # prints "booh" del len print f() # prints 0 again

Worse, instead if explicitly overriding len in the module, it could have been an assignment to main.len in some other module.

We've been thinking on how to deal with this for years, since nobody really likes it in all its freedom.

-- --Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list