Inspect and / or delete cached properties#211
Open
francois-durand wants to merge 4 commits into
Open
Conversation
* All cached properties derive from a parent class ``CachedProperty``, so that we can use isinstance to identify them. * Add function ``cached_properties``: iterate over the cached properties of an object. * Add function ``cached_properties_computed``: iterate over the cached properties that are already computed. * Add function ``delete_cache``: empty the whole cache of an object. * Add decorator ``property_deleting_cache``: a property that deletes the cache when it is set or deleted.
* Use Black. * ``property_deleting_cache`` uses the function for its side effects, even if its return value is ignored. * ``property_deleting_cache_2``: proposition or alternate syntax.
* Remove ``cached_properties_computed``, because it is now a trivial combination of ``cached_properties`` and ``is_cached``.
* Update Readme: * Add new functions (un_cache, delete_cache, etc.). * Replace the monopoly running example by a more generic example. * Add a notebook "readme companion" to test the code of the readme.
Author
|
No reaction? :'-( |
Author
|
Bump. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi @pydanny,
Thank you for this package! This pull request addresses issues #32 and #196. Here is a sum-up:
CachedProperty, so that we can useisinstanceto identify them easily.cached_properties: iterate over the cached properties of an object.is_cached: whether a cached property is already cached.un_cache: empty the cache for a cached property. As @Tinche noted, it avoids exposing an implementation detail.delete_cache: empty the whole cache of an object.property_deleting_cache: a property that deletes the cache when it is set or deleted. A typical example of application is given in the docstring (and in the readme).For
property_deleting_cache, some people may find it strange to have this parameterfuncwhose output is ignored. As a matter of fact, in most use cases, I guess that its code will bepass. I hesitated a bit and I also implemented another syntax option inproperty_deleting_cache_2. However, I still prefer option 1 because its usage as a decorator is more similar to what we use for regular properties and cached properties. Tell me which one you prefer (and just remove the other one)!In the readme, I suggest replacing the running example about monopoly by a more generic example. This monopoly example seemed quite unnatural to me, and I hope that the new one is more telling, even if it is a bit less funny.
This is my first pull request ever so do not hesitate to tell me if I did something wrong :-). Best,
François