Fix my dumb habit of importing the package into setup.py
[cached-property.git] / cached_property.py
1 # -*- coding: utf-8 -*-
2
3 __author__ = 'Daniel Greenfeld'
4 __email__ = 'pydanny@gmail.com'
5 __version__ = '0.1.3'
6 __license__ = 'BSD'
7
8
9 class cached_property(object):
10 """ A property that is only computed once per instance and then replaces
11 itself with an ordinary attribute. Deleting the attribute resets the
12 property. """
13
14 def __init__(self, func):
15 self.__doc__ = getattr(func, '__doc__')
16 self.func = func
17
18 def __get__(self, obj, cls):
19 if obj is None:
20 return self
21 value = obj.__dict__[self.func.__name__] = self.func(obj)
22 return value