Dear all, First of all thanks to Simon for his optimization of the cached_method decorator. Lots of code are now much faster. However it seems that there is a problem using it with inheritance. I need to overload a cached method to provide a default value for its argument. Here is a code reproducing the problem:
class A(SageObject): @cached_method def toto(self, arg): return arg+1 class B(A): def toto(self, arg=2): return super(B, self).toto(arg) class C(A): def toto(self, arg=2): return A.toto(self, arg) Then: sage: b = B() sage: b.toto() 3 sage: b.toto() --------------------------------------------------------------------------- KeyError Traceback (most recent call last) /home/data/Sage-Install/sage-4.6.2/devel/sage-combinat/sage/categories/<ipython console> in <module>() /home/florent/src/Sage/sage/local/lib/python2.6/site-packages/sage/misc/cachefunc.pyc in __call__(self, *args, **kwds) 549 k = self._default_key 550 except AttributeError: --> 551 k = self._default_key = self.get_key() 552 try: 553 return self.cache[k] /home/florent/src/Sage/sage/local/lib/python2.6/site-packages/sage/misc/cachefunc.pyc in get_key(self, *args, **kwds) 601 if self._inst_in_key: 602 return (self._instance,self._argumentfixer.fix_to_pos(*args,**kwds)) --> 603 return self._argumentfixer.fix_to_pos(*args,**kwds) 604 605 def __get__(self, inst, cls=None): /home/florent/src/Sage/sage/local/lib/python2.6/site-packages/sage/misc/function_mangling.so in sage.misc.function_mangling.ArgumentFixer.fix_to_pos (sage/misc/function_mangling.c:1423)() KeyError: 'arg' In this case, during the call super(B, self).toto(arg) the method b.toto is replaced by an attribute which overload it. Using the C class thing are even more weird: sage: c = C() sage: c.toto() [...] TypeError: toto() takes exactly 2 arguments (3 given) So the question are: is this a known bug ? Is this expected ? Are there any idea to solve the problem ? Cheers, Florent -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org