Decorating methods - where do my arguments go?

Michele Simionato michele.simionato at gmail.com
Tue May 12 03:01:10 EDT 2009


On May 12, 8:54 am, Mikael Olofsson <mik... at isy.liu.se> wrote:
> Peter Otten wrote:
> > I usually use decorator functions, but I think the following should work,
> > too:
>
> > class deco(object):
> >     def __init__(self, func):
> >         self._func = func
> >     def __call__(self, *args):
> >         print "Decorator:", args
> >         self._func(*args)
> >     def __get__(self, *args):
> >         return deco(self._func.__get__(*args))
>
> This looks like a winner to me. It is elegant, works for functions as
> well as for methods, and does not mess with the internals of the
> decorator which avoids the problems that Duncan pointed out.

Still it turns something which is a function into an object and you
lose the
docstring and the signature. pydoc will not be too happy with this
approach.



More information about the Python-list mailing list