From 59a6292eb2f7a2b4e0c2f2534d14b48a13c4fe2d Mon Sep 17 00:00:00 2001 From: George Sakkis Date: Tue, 21 Apr 2015 03:21:36 +0300 Subject: [PATCH] Revert cached_property_with_ttl/threaded_cached_property_with_ttl to settable just like cached_property/threaded_cached_property --- cached_property.py | 3 +++ tests/test_cached_property.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/cached_property.py b/cached_property.py index 45654b8..ee896ae 100644 --- a/cached_property.py +++ b/cached_property.py @@ -96,6 +96,9 @@ class cached_property_with_ttl(object): def __delete__(self, obj): obj.__dict__.pop(self.__name__, None) + def __set__(self, obj, value): + obj.__dict__[self.__name__] = (value, time()) + def _prepare_func(self, func): self.func = func if func: diff --git a/tests/test_cached_property.py b/tests/test_cached_property.py index 725a87e..1bca7ab 100644 --- a/tests/test_cached_property.py +++ b/tests/test_cached_property.py @@ -116,6 +116,13 @@ class TestCachedProperty(unittest.TestCase): self.assert_cached(Check(), None) + def test_set_cached_property(self): + Check = CheckFactory(self.cached_property_factory) + check = Check() + check.add_cached = 'foo' + self.assertEqual(check.add_cached, 'foo') + self.assertEqual(check.cached_total, 0) + def test_threads(self): Check = CheckFactory(self.cached_property_factory, threadsafe=True) check = Check() -- 2.30.2