Turning a signature-changing decorator into a signature-preserving one

Gustavo Narea me at gustavonarea.net
Mon Feb 16 11:58:25 EST 2009


On Feb 16, 5:18 pm, Michele Simionato <michele.simion... at gmail.com>
wrote:
> On Feb 16, 4:59 pm, Gustavo Narea <m... at gustavonarea.net> wrote:
>
>
>
> > I've not seen anything special in Pylons or TurboGears 2 decorators,
> > except that they are all functions that use the decorator package --
> > while my decorator is a class that doesn't use the decorator package
> > yet.
>
> > My attempt to turn that decorator into a signature preserving one
> > using the decorator packages fails even on TurboGears 2. As of
> > decorator 3.0.1, I get this error:
> >     TypeError: You are decorating a non function: <unbound method
> > SecurePanel.__before__>
>
> > Isn't this caused by the fact that my decorator is a class, or the way
> > such a class is defined (whose code is in the first post of the
> > thread)? I can turn it into a function because I'm sure I'll work --
> > although I wanted a class to make it easier to customize.
>
> > Thanks.
>
> The decorator class is fine, the error in clearly in what you pass to
> the decorator.
> You are trying to decorate an unbound method SecurePanel.__before__:
> are you
> sure this is really what you want to decorate? Are you decorating
> automatically all methods
> of SecurePanel? I have already mentioned it, but you can extract the
> underlying function
> from the method by using  SecurePanel.__before__.im_func if you really
> want.

Thank you very much, it works with SecurePanel.__before__.im_func!



More information about the Python-list mailing list