| 52 | |
| 53 | |
| 54 | class 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 | |
| 72 | PRIMITIVE_TYPES = (list, float, int, bool, datetime, date, str, file_type) |
nothing calls this directly
no outgoing calls
no test coverage detected