Hi Simon,

> > But my patches do not solve the problem either -- only the error
> > message for b is different:
> > sage: b = B()
> > sage: b.toto()
> > 3
> > sage: b.toto()
> > Traceback (most recent call last):
> > ...
> > TypeError: toto() takes exactly 2 arguments (1 given)
> > 
> > I can explain that example: If you call b.toto() the first time, then
> > the cached method defined in class A is called.
> > One of the things a cached method does with my patch is to replace
> > itself by a CachedMethodCaller (without the patch, the
> > CachedMethodCaller would be constructed over and over again, which is
> > a waste of time and may break the cache).
> > Hence, if you call b.toto() the second time, it becomes a different
> > method, expecting different arguments (the default argument is gone).
> 
> Yes ! That's what I figured out.

Just to let you know, I tried the following work around:

class A(SageObject):
    @cached_method
    def toto(self, arg):
        return arg+1
class CC(A):
    toto_cached = cached_method(A.toto.f)
    def toto(self, arg=2):
        return self.toto_cached(arg)

but since A.toto.f.__name__ is still toto. It doesn't work. However the
following works (on unpatched sage-4.6.2):

def change_name(fun, name):
    fun = copy(fun)
    fun.__name__ = name
    return fun

class CC(A):
    toto_cached = cached_method(change_name(A.toto.f, "toto_cached"))
    def toto(self, arg=2):
        return self.toto_cached(arg)

I'll try with your patch as well.

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

Reply via email to