diff options
-rw-r--r-- | decorators.py | 7 | ||||
-rw-r--r-- | test/unittest_decorators.py | 13 |
2 files changed, 18 insertions, 2 deletions
diff --git a/decorators.py b/decorators.py index 336af9d..36ebe14 100644 --- a/decorators.py +++ b/decorators.py @@ -38,7 +38,6 @@ class cached_decorator(object): cache = _SingleValueCache(callableobj, self.cacheattr) elif self.keyarg: cache = _MultiValuesKeyArgCache(callableobj, self.keyarg, self.cacheattr) - print 'hop' else: cache = _MultiValuesCache(callableobj, self.cacheattr) return cache.closure() @@ -119,7 +118,11 @@ def cached(callableobj=None, keyarg=None, **kwargs): def clear_cache(obj, funcname): """Function to clear a cache handled by the cached decorator.""" - getattr(obj, funcname).clear(obj) + cls = obj.__class__ + member = getattr(cls, funcname) + if isinstance(member, property): + member = member.fget + member.clear(obj) def copy_cache(obj, funcname, cacheobj): """Copy cache for <funcname> from cacheobj to obj.""" diff --git a/test/unittest_decorators.py b/test/unittest_decorators.py index b3321fc..1f92d55 100644 --- a/test/unittest_decorators.py +++ b/test/unittest_decorators.py @@ -102,5 +102,18 @@ class DecoratorsTC(TestCase): clear_cache(foo, 'foo') self.assertFalse(hasattr(foo, '_foo')) + def test_cached_property(self): + class Foo(object): + @property + @cached(cacheattr=u'_foo') + def foo(self): + """ what's up doc ? """ + foo = Foo() + foo.foo + self.assertEqual(foo._foo, None) + clear_cache(foo, 'foo') + self.assertFalse(hasattr(foo, '_foo')) + + if __name__ == '__main__': unittest_main() |