Hi Simon, > 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?
Yes that what I was expecting. In the category FiniteEnumeratedSets the class ParentMethods contains various default implementation. For examples: def _cardinality_from_iterator(self): [...] def _cardinality_from_list(self): [...] #Set cardinality to the default implementation cardinality = _cardinality_from_iterator I was trying to put a cache on _cardinality_from_iterator but is doesn't work. For this specific usecase I understand that I can write: def _cardinality_from_iterator(self): [...] def _cardinality_from_list(self): [...] #Set cardinality to the default implementation cardinality = cached_method(_cardinality_from_iterator, name='cardinality') > 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? For that kind of behavior I would expect having a syntax like def _uncached(...) cached1 = cached_method(_uncached, name = cached1) cached1 = cached_method(_uncached, name = cached2) that is building two CachedMethodObject. So do you think we should warn the user that the first syntax doesn't work and give him the correct solution ? Or is there an easy way to have it working ? Cheers, Florent -- 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.