[Python-Dev] 2.5 and beyond

Tim Peters tim.peters at gmail.com
Sat Jul 1 01:39:03 CEST 2006


[Andrew Koenig]
> ...
> Incidentally, I think that lexical scoping would also deal with the problem
> that people often encounter in which they have to write things like "lambda
> x=x:" where one would think "lambda x:" would suffice.

They _shouldn't_ encounter that at all anymore.  For example,

>>> def f(x):
...     return lambda: x+1
>>> f(3)()
4

works fine in modern Pythons.  Earlier Python's had a no-exceptions
3-scope implementation (local, global, builtin), and in those the "x"
in the lambda body was "not local" (was either global or builtin,
although the compiler couldn't tell which of those two it was).  In
_those_ Pythons people had to write "lambda x=x: x+1" instead, to suck
the binding of the outer x into the lambda body, but if people are
still doing that they're confused.  Modern Pythons do have lexical
scoping + global + builtin, although there's no way to spell "rebind a
name local to an outer scope from within an inner scope".


More information about the Python-Dev mailing list