Decorators inside of class and decorator parameters

MR ptwobrussell at gmail.com
Sun Jan 14 12:10:24 EST 2007


Wow. Really neat stuff there. memoize seems especially cool since you
can get lots of nice dynamic programming benefits "for free" (sorry if
I just stated the obvious, but I thought was was especially cool.)


Michele Simionato wrote:
> Gabriel Genellina wrote:
> > see this article by M. Simoniato
> > http://www.phyast.pitt.edu/~micheles/python/documentation.html for a better
> > way using its decorator factory.
>
> Actually the name is Simionato ;)
> I have just released version 2.0, the new thing is an update_wrapper
> function similar to the one
> in the standard library, but with the ability to preserve the signature
> on demand. For instance
>
> def traced(func):
>    def wrapper(*args, **kw):
>        print 'calling %s with args %s, %s' % (func, args, kw)
>        return func(*args, **kw)
>   return update_wrapper(wrapper, func, create=False)
>
> works exactly as functools.update_wrapper (i.e. copies__doc__,
> __module__,etc. from func to wrapper without
> preserving the signature), whereas update_wrapper(wrapper, func,
> create=True) creates a new wrapper
> with the right signature before copying the attributes.
> 
>  Michele Simionato




More information about the Python-list mailing list