Re: Decorating class member functions

2007-05-04 Thread Rhamphoryncus
On May 3, 10:34 pm, Peter Otten <[EMAIL PROTECTED]> wrote: > The problem is not that you are decorating a method but that you are trying > to use a callable class instance as a method. For that to work the class > has to implement the descriptor protocol, see > > http://users.rcn.com/python/downloa

Re: Decorating class member functions

2007-05-04 Thread Andy Terrel
Thanks Peter and 7stud. That is the solution that really works for me. -- http://mail.python.org/mailman/listinfo/python-list

Re: Decorating class member functions

2007-05-03 Thread 7stud
On May 3, 7:21 pm, Andy Terrel <[EMAIL PROTECTED]> wrote: > Okay does anyone know how to decorate class member functions? > > The following code gives me an error: > > Traceback (most recent call last): > File "decorators2.py", line 33, in > s.update() > File "decorators2.py", line 13, in

Re: Decorating class member functions

2007-05-03 Thread Peter Otten
Andy Terrel wrote: > Okay does anyone know how to decorate class member functions? > > The following code gives me an error: > > Traceback (most recent call last): > File "decorators2.py", line 33, in > s.update() > File "decorators2.py", line 13, in __call__ > retval = self.fn.__ca

Re: Decorating class member functions

2007-05-03 Thread Steven D'Aprano
On Thu, 03 May 2007 19:28:52 -0700, Andy Terrel wrote: > I just need to keep the state around. I make a call to some function > that is pretty expensive so I want to save it as a member during the > __init__ of the decorator. > > Yeah I'm afraid it can't be done either, that's why I asked the gro

Re: Decorating class member functions

2007-05-03 Thread Andy Terrel
not quite as elegant but here is a workaround... Thanks Virgil for taking some time to think about it. --- class Bugger (object): def __init__ (self, module): print "Entering __init__" self.module = module self.verb = 0 def instrument (module_name): def wrapper(f)

Re: Decorating class member functions

2007-05-03 Thread Jorge Godoy
Andy Terrel <[EMAIL PROTECTED]> writes: > I just need to keep the state around. I make a call to some function > that is pretty expensive so I want to save it as a member during the > __init__ of the decorator. > > Yeah I'm afraid it can't be done either, that's why I asked the group. Have you lo

Re: Decorating class member functions

2007-05-03 Thread Andy Terrel
I just need to keep the state around. I make a call to some function that is pretty expensive so I want to save it as a member during the __init__ of the decorator. Yeah I'm afraid it can't be done either, that's why I asked the group. -- http://mail.python.org/mailman/listinfo/python-list

Re: Decorating class member functions

2007-05-03 Thread Virgil Dupras
On May 3, 9:21 pm, Andy Terrel <[EMAIL PROTECTED]> wrote: > Okay does anyone know how to decorate class member functions? > > The following code gives me an error: > > Traceback (most recent call last): > File "decorators2.py", line 33, in > s.update() > File "decorators2.py", line 13, in

Re: Decorating class member functions

2007-05-03 Thread Virgil Dupras
On May 3, 9:33 pm, Virgil Dupras <[EMAIL PROTECTED]> wrote: > On May 3, 9:21 pm, Andy Terrel <[EMAIL PROTECTED]> wrote: > > > > > Okay does anyone know how to decorate class member functions? > > > The following code gives me an error: > > > Traceback (most recent call last): > > File "decorators

Re: Decorating class member functions

2007-05-03 Thread Virgil Dupras
On May 3, 9:21 pm, Andy Terrel <[EMAIL PROTECTED]> wrote: > Okay does anyone know how to decorate class member functions? > > The following code gives me an error: > > Traceback (most recent call last): > File "decorators2.py", line 33, in > s.update() > File "decorators2.py", line 13, in

Re: Decorating class member functions

2007-05-03 Thread Andy Terrel
Oh I should mention the decorator needs to have some notion of state (such as with the above class) -- http://mail.python.org/mailman/listinfo/python-list

Decorating class member functions

2007-05-03 Thread Andy Terrel
Okay does anyone know how to decorate class member functions? The following code gives me an error: Traceback (most recent call last): File "decorators2.py", line 33, in s.update() File "decorators2.py", line 13, in __call__ retval = self.fn.__call__(*args,**kws) TypeError: update()