For @cached_property decorated methods, is there a built-in way to iterate through all of these attributes? My use case is that I'd like to clear all cached properties with the del operator without bookkeeping for them manually in something like a list.
Here's a canned example. __init__ could do something fancy like load data from a file that needs to be reloaded later, which means all cached properties would need to be recomputed.
class MyData:
def __init__(self):
self.a = 0
self.b = 0
@cached_property
def sum(self):
return self.a + self.b
def reload(self):
# Is there anything keeping track of cached properties?
for prop in self.__something__.cached_properties:
del prop