Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Turning a signature-changing decorator into a signature-preservingone

Reply
Thread Tools

Turning a signature-changing decorator into a signature-preservingone

 
 
Michele Simionato
Guest
Posts: n/a
 
      02-16-2009
On Feb 16, 4:29*pm, Gustavo Narea <m...@gustavonarea.net> wrote:
> On Feb 16, 4:18 pm, Michele Simionato <michele.simion...@gmail.com>
> wrote:
>
> > Yes, I am saying don't mess with the internal mechanism of Pylons and
> > leave it as
> > it was. Or was it broken from the beginning? The only reason I see for
> > you
> > to touch those things is if you are a Pylons core developer.

>
> It was broken from the beginning on Pylons.
>
> I'm a TurboGears 2 core developer, and TurboGears is powered by Pylons
> as of version 2. The decorator has always worked in TurboGears because
> of the way TG finds the action arguments, but now I'm working to make
> it work in Pylons too, but this is the only problem that has stopped
> me from making it work under Pylons.
>
> Thanks.


I see. I would ask on the Pylons list. I suspect a bound method is
passed and that you will
need to extract the corresponding function with .im_func, then making
sure that you pass
the self argument correctly. But this is wild guess since I have no
idea of how Pylons decorators
work internally as compared to TurboGears decorators.
 
Reply With Quote
 
 
 
 
Gustavo Narea
Guest
Posts: n/a
 
      02-16-2009
On Feb 16, 4:40 pm, Michele Simionato <michele.simion...@gmail.com>
wrote:
> > It was broken from the beginning on Pylons.

>
> > I'm a TurboGears 2 core developer, and TurboGears is powered by Pylons
> > as of version 2. The decorator has always worked in TurboGears because
> > of the way TG finds the action arguments, but now I'm working to make
> > it work in Pylons too, but this is the only problem that has stopped
> > me from making it work under Pylons.

>
> > Thanks.

>
> I see. I would ask on the Pylons list. I suspect a bound method is
> passed and that you will
> need to extract the corresponding function with .im_func, then making
> sure that you pass
> the self argument correctly. But this is wild guess since I have no
> idea of how Pylons decorators
> work internally as compared to TurboGears decorators.


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.
 
Reply With Quote
 
 
 
 
Gustavo Narea
Guest
Posts: n/a
 
      02-16-2009
On Feb 16, 4:59 pm, Gustavo Narea <m...@gustavonarea.net> wrote:
> On Feb 16, 4:40 pm, Michele Simionato <michele.simion...@gmail.com>
> wrote:
>
>
>
> > > It was broken from the beginning on Pylons.

>
> > > I'm a TurboGears 2 core developer, and TurboGears is powered by Pylons
> > > as of version 2. The decorator has always worked in TurboGears because
> > > of the way TG finds the action arguments, but now I'm working to make
> > > it work in Pylons too, but this is the only problem that has stopped
> > > me from making it work under Pylons.

>
> > > Thanks.

>
> > I see. I would ask on the Pylons list. I suspect a bound method is
> > passed and that you will
> > need to extract the corresponding function with .im_func, then making
> > sure that you pass
> > the self argument correctly. But this is wild guess since I have no
> > idea of how Pylons decorators
> > work internally as compared to TurboGears decorators.

>
> 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.



This is another attempt, where the decorator is a still a class but
uses an auxiliary function:
http://paste.chrisarndt.de/paste/38b...8d424e1f2d4182

However, that raises this exception:
http://paste.chrisarndt.de/paste/f90...1752a7?wrap=no
 
Reply With Quote
 
Michele Simionato
Guest
Posts: n/a
 
      02-16-2009
On Feb 16, 4:59*pm, Gustavo Narea <m...@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.
 
Reply With Quote
 
Gustavo Narea
Guest
Posts: n/a
 
      02-16-2009
On Feb 16, 5:18 pm, Michele Simionato <michele.simion...@gmail.com>
wrote:
> On Feb 16, 4:59 pm, Gustavo Narea <m...@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!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make a method into a property without using the @property decorator Phlip Python 2 10-23-2010 05:25 PM
Decorator to inject function into __call__ of a class Jon Clements Python 8 03-13-2010 07:48 PM
Why doesnt __getattr__ with decorator dont call __get_method in decorator glomde Python 5 03-29-2007 02:48 PM
Turning rows into columns Erik Cruz ASP .Net 2 09-25-2004 08:13 AM
Decorator for Binding Globals into Constants Raymond Hettinger Python 0 09-09-2004 08:16 AM



Advertisments