Source code for psy.utils.tools
# coding=utf-8
[docs]class cached_property(object):
"""
# 从django抄的详见同名函数
"""
def __init__(self, func, name=None):
self.func = func
self.__doc__ = getattr(func, '__doc__')
self.name = name or func.__name__
def __get__(self, instance, type=None):
if instance is None:
return self
res = instance.__dict__[self.name] = self.func(instance)
return res