Hi Florent, On 2013-01-30, Florent Hivert <florent.hiv...@lri.fr> wrote: > It's not clear to me from the documentation if the following behavior is a bug > or a known bad use of cached method: > > class Bla(object): > @cached_method > def truc(self): > print "Computing truc" > return 1 > trac = truc > > sage: b = Bla() > sage: b.truc() > Computing truc > 1 > sage: b.truc() > 1 > sage: b.truc() > 1 > sage: b.trac() > Computing truc > 1 > sage: b.trac() > Computing truc > 1 > sage: b.trac() > Computing truc > 1 > > If it is not considered as a bug, I think the documentation should make it > clear that it is a misuse and what is the correct (and fastest) way to write > it.
A cached method uses the name of the wrapped method to determine the name of an attribute used for storing the cache. So, defining a cached method under one name and storing it under another name is asking for trouble. I think at some point we have discussed introducing a way to rename cached methods, which is what would be needed here. I don't know whether it would be possible to do that automatically, though, by defining trac=truc as you did in your class definition. But could you please explain what you expect from the definition trac=truc? Do you expect that ``b.trac is b.truc``, hence, the two cached methods are identical? In particular, they would share theiry cache, so that calling b.truc() and then b.trac() would trigger only *one* computation? Or do you expect that ``b.trac is not b.truc``, so that calling b.truc() and then b.trac() triggers *two* computations, whose results are cached in distinct locations? Best regards, Simon -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel?hl=en. For more options, visit https://groups.google.com/groups/opt_out.