我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用werkzeug.utils.cached_property()。
def test_cached_property(self): foo = [] class A(object): def prop(self): foo.append(42) return 42 prop = utils.cached_property(prop) a = A() p = a.prop q = a.prop self.assert_true(p == q == 42) self.assert_equal(foo, [42]) foo = [] class A(object): def _prop(self): foo.append(42) return 42 prop = utils.cached_property(_prop, name='prop') del _prop a = A() p = a.prop q = a.prop self.assert_true(p == q == 42) self.assert_equal(foo, [42])
def test_cached_property_doc(self): @utils.cached_property def foo(): """testing""" return 42 self.assert_equal(foo.__doc__, 'testing') self.assert_equal(foo.__name__, 'foo') self.assert_equal(foo.__module__, __name__)