[Python-ideas] Allow lambda decorators
Lie Ryan
lie.1296 at gmail.com
Mon Feb 9 13:44:20 CET 2009
On Sun, 08 Feb 2009 18:08:25 -1000, Carl Johnson wrote:
<snip>
I can't really comprehend the feature you're describing (TLDR), but
knowing that decorator is merely a syntax sugar for function calling to a
function:
@lambdafunc
def func(foo): pass
is equal to
def func(foo): pass
func = lambdafunc(func)
why don't you do this instead:
lambdafunc(lambda foo: -foo)
it is perfectly readable and is a more functional approach than decorator.
Also for the first example you gave:
>>> def func_maker():
... fs = []
... for i in range(10):
... def f():
... return i
... fs.append(f)
... return fs
why not? (untested)
>>> from functools import partial
>>> def func_maker():
... def f(j):
... return j
... fs = []
... for i in range(10):
... fs.append(partial(f, i))
... return fs
...
Closure is already confusing enough for most people. Dynamic creation of
closure, which is allowed because of python's way of defining function is
an abuse of closure IMHO.
More information about the Python-ideas
mailing list