python类cached_property()的实例源码

misc_test.py 文件源码 项目:webapp2 作者: GoogleCloudPlatform 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_cached_property(self):
        count = [0]

        class Foo(object):
            @webapp2.cached_property
            def bar(self):
                count[0] += 1
                return count[0]

        self.assertTrue(isinstance(Foo.bar, webapp2.cached_property))

        foo = Foo()
        self.assertEqual(foo.bar, 1)
        self.assertEqual(foo.bar, 1)
        self.assertEqual(foo.bar, 1)


问题


面经


文章

微信
公众号

扫码关注公众号