Opened 8 years ago
Closed 8 years ago
#14278 closed enhancement (fixed)
Clear the cache of a cached representation
Reported by: | SimonKing | Owned by: | jason |
---|---|---|---|
Priority: | major | Milestone: | sage-5.9 |
Component: | misc | Keywords: | |
Cc: | Merged in: | sage-5.9.beta2 | |
Authors: | Simon King | Reviewers: | Travis Scrimshaw |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | #14054 | Stopgaps: |
Description
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...
Attachments (2)
Change History (10)
comment:1 Changed 8 years ago by
- Status changed from new to needs_review
Changed 8 years ago by
comment:2 Changed 8 years ago by
comment:3 Changed 8 years ago by
The failure reported be one of the patchbots was a maxima crash. I suppose that's unrelated. In any case, I kicked the bot, so, we will see of the maxima crash is reproducible.
comment:4 Changed 8 years ago by
Hooray, we now have a green blob!
comment:5 Changed 8 years ago by
Hey Simon,
Could you also add tests with a __classcall_private__()
? Thanks.
Changed 8 years ago by
comment:6 Changed 8 years ago by
Is the test that I added in my second patch appropriate?
Apply trac_14278-clear_cached_presentation.patch trac_14278-doctest.patch
comment:7 Changed 8 years ago by
- Reviewers set to Travis Scrimshaw
- Status changed from needs_review to positive_review
Yep. Looks good to me. Thank you.
comment:8 Changed 8 years ago by
- Merged in set to sage-5.9.beta2
- Resolution set to fixed
- Status changed from positive_review to closed
I updated the patch: The additional (class) method made one test in my coercion tutorial fail, that tests for the number of methods.