persistent deque version 4
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sat May 24 15:54:12 EDT 2008
En Thu, 22 May 2008 12:20:56 -0300, inhahe <inhahe at gmail.com> escribió:
> I thought about the fact that a decorator is merely syntactic sugar, so it
> shouldn't have any closure magic that I can't make myself, and I realized
> that I could have done it the following way:
>
> def makefunc(func):
> def func2(instance, *args):
> result = func(instance, *args)
> instance.save()
> return result
> return func2
Using functools.wraps is better because it helps to preserve the function name and signature:
def makefunc(func):
@wraps(func)
def wrapper(self, *args, **kwds):
result = func(self, *args, **kwds)
self.save()
return result
return wrapper
--
Gabriel Genellina
More information about the Python-list
mailing list