python-by-example-150-chall.../venv/lib/python3.6/site-packages/lazy_object_proxy/utils.py

14 lines
291 B
Python
Raw Permalink Normal View History

2019-08-04 20:26:35 +08:00
def identity(obj):
return obj
class cached_property(object):
def __init__(self, func):
self.func = func
def __get__(self, obj, cls):
if obj is None:
return self
value = obj.__dict__[self.func.__name__] = self.func(obj)
return value