Why is class decorator on method loosing self?

c james cjames at callone.net
Tue Nov 21 09:00:03 EST 2006


I want to use the LRU decorator posted at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498110
on a class method.  However, it complains about missing arguments. The 
missing argument is `self`.  I could use @classmethod but what I really 
need is an instance method.  I don't see how and was hoping someone else 
might know the way.

Here is an example with taking that recipe as lru.py

import lru

class Foo(object):
     def banner(self):
         print "Testing method"

     @memoize(3)
     def min_max(self, sequence):
         self.banner()
         return min(sequence), max(sequence)

foo = Foo()
print foo.min_max([9,7,5,3,1])


Traceback (most recent call last):
...
   File "lru.py", line 48, in __call__
     value = self.func(*args, **kwargs)
TypeError: min_max() takes exactly 2 arguments (1 given)




More information about the Python-list mailing list