-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: simplify base CoordinateHandler implementation (cached properties) #4435
RFC: simplify base CoordinateHandler implementation (cached properties) #4435
Conversation
e65db54
to
4c5c6ce
Compare
well also even if I wrote them today I didn't know it was in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
dpj[ax] = None | ||
self._data_projection = dpj | ||
return dpj | ||
return {ax: None for ax in self.axis_order} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is definitely not a user-facing issue, but from my perspective, I am wondering -- is it possible to invalidate the cached property at runtime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The result of a cached_property can be mutated transparently. Does this answer your question ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I guess you were wondering if it was possible to reset the property to its initial state.
In which case the answer is: not to my knowledge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... and a better answer yet, from the docs:
The cached value can be cleared by deleting the attribute. This allows the cached_property method to run again.
PR Summary
Some low-hanging simplifications I found while working on #4179
functools.cached_property
wasn't available before Python 3.8 which explains why these properties didn't use it already.As a side bonus, I also discovered and replaced two occurrences of
abc.abstractproperty
, which is deprecated since Python 3.3