[Python-ideas] Allow lambda decorators

Terry Reedy tjreedy at udel.edu
Mon Feb 9 07:03:39 CET 2009

Carl Johnson wrote:
> A few months back there was a discussion of how code like this gives 
> "surprising" results because of the scoping rules:

And solutions were given.

>  >>> def func_maker():
> ...     fs = []
> ...     for i in range(10):
> ...         def f():
> ...             return i
> ...         fs.append(f)
> ...     return fs
> ...
>  >>> [f() for f in func_maker()]
> [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
> Various syntax changes were proposed to get around this, but nothing 
> ever came of it.

a) there is already a trivial way to get the result wanted;
b) proposals are wrapped in trollish claims;
c) perhaps no proposer is really serious.

To me, one pretty obvious way to define default non-parameters would be
to follow the signature with "; <name = expr>+".  Where is the PEP, though?

Enough already.


> Thinking about it some more, I've realized that the change I proposed is 
> unnecessary, since we already have the decorator syntax. So, for 
> example, the original function can be made to act with the "expected" 
> scoping by using an each_in function defined as follows:

Such a mess to avoid using the current syntax
Like Guido, my head hurt trying to read it, so I quit.

> What do other people think?


Terry Jan Reedy

More information about the Python-ideas mailing list