id summary reporter owner description type status priority milestone component resolution keywords cc merged author reviewer upstream work_issues branch commit dependencies stopgaps
14278 Clear the cache of a cached representation Simon King Jason Grout "I have seen doctests that try to demonstrate how to clear a cache of class instances. See sage/modular/abvar/abvar_ambient_jacobian.py, for example.
This made me think: It would be nice to be able to define a class method for `CachedRepresentation` that clears the cache from all instances of this class.
With my patch, the following works:
{{{
sage: class A(UniqueRepresentation):
... def __init__(self, x):
... pass
sage: class B(A):
... @staticmethod
... def __classcall__(cls, *args, **kwds):
... return super(B,cls).__classcall__(cls,*args,**kwds)
sage: class C(B): pass
sage: a = A(1)
sage: b = B(2)
sage: c = C(3)
sage: a is A(1)
True
sage: b is B(2)
True
sage: c is C(3)
True
sage: B._clear_cache_()
sage: a is A(1)
True
sage: b is B(2)
False
sage: c is C(3)
False
}}}
Note that B overloads `__classcall__`, but nevertheless the _clear_cache_ methods finds the cache and removes all instances of B and its subclass C.
Sorry, I have no idea what component to choose. Let it be misc, then..." enhancement closed major sage-5.9 misc fixed sage-5.9.beta2 Simon King Travis Scrimshaw N/A #14054