#35743: Add a method to cached_property for clearing its cached value
-------------------------------+-----------------------------------------
Reporter: Jae Hyuck Sa | Owner: Jae Hyuck Sa
Type: New feature | Status: assigned
Component: Utilities | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-----------------------------------------
Comment (by Simon Charette):
Given that there appears to be a consensus to move to
`functools.cached_property` once we drop support for Python 3.11 (see
#30949) I would see the addition of this method as a step that prevents us
from doing that.
What benefits are there in doing
{{{#!python
SomeClass.some_cached_property.clear_cache(some_class_instance)
}}}
over
{{{#!python
some_class_instance.__dict__.pop("some_cached_property", None)
}}}
when you can't be sure the property has been cached and `del` or `delattr`
otherwise?
It is a pattern
[https://github.com/search?q=repo%3Adjango%2Fdjango+%22__dict__.pop%22&type=code
used extensively in the code base] but that we could admittedly document
better (#30278)
--
Ticket URL: <https://code.djangoproject.com/ticket/35743#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070191d234713c-a5a72500-bfd8-47d0-b58b-93c75b0e9ea4-000000%40eu-central-1.amazonses.com.