I'm using the functools.cached_property to memoize some functions.
but it seems not to be supporting setter.
for example
class User
@cached_property
def name(self):
return self._name
@name.setter
def name(self, val):
self._name = val
but when importing i encountered AttributeError: 'cached_property' object has no attribute 'setter'
@cached_property is designed for immutable values. You cannot expect that this decorator will mimic all features from standard property. In python doc you can find: "The mechanics of cached_property() are somewhat different from property(). A regular property blocks attribute writes unless a setter is defined. In contrast, a cached_property allows writes."
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.