MCPcopy Create free account
hub / github.com/bundesAPI/smard-api / cached_property

Class cached_property

python-client/deutschland/smard/model_utils.py:54–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52
53
54class cached_property(object):
55 # this caches the result of the function call for fn with no inputs
56 # use this as a decorator on function methods that you want converted
57 # into cached properties
58 result_key = "_results"
59
60 def __init__(self, fn):
61 self._fn = fn
62
63 def __get__(self, instance, cls=None):
64 if self.result_key in vars(self):
65 return vars(self)[self.result_key]
66 else:
67 result = self._fn()
68 setattr(self, self.result_key, result)
69 return result
70
71
72PRIMITIVE_TYPES = (list, float, int, bool, datetime, date, str, file_type)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected