
Scott Dial schrieb:
Is is really that common? In this case, you are misrepresenting the pattern. The appropriate version of this would require references to _f to make it's signature match that of f's, and therefore this entire argument is specious. In reality, the number of times you can get away with returning a truly anonymous function (that isn't a glorified lambda) is rare, I think.
def deco(f): def _f(*args,**kawrgs): ... functools.update_wrapper(_f, f) return _f
Or:
def deco(f): @functools.wraps(f) def _f(*args,**kawrgs): ... return _f
Even in the second case, it would be awkward to inline with the return statement because of the need to invoke a decorator.
ic. Ok, maybe something even more different: curried functions. def plus2(f)(x): return f(x+2) @plus2 def foo(x): ... Or I don't know. Just a thought. And yes, you cannot user functools.wraps on that either. And this is just plain ugly/utter crap: def plus2(f) @functools.wraps(f) def (x): return f(x+2) -panzi