Made cached_property to behave as property when accessed via class.
This commit is contained in:
Tomek Paczkowski 2013-02-23 23:20:00 +01:00
parent 83ecb7b145
commit b88abd6840
2 changed files with 31 additions and 2 deletions

View file

@ -39,7 +39,9 @@ class cached_property(object):
def __init__(self, func):
self.func = func
def __get__(self, instance, type):
def __get__(self, instance, type=None):
if instance is None:
return self
res = instance.__dict__[self.func.__name__] = self.func(instance)
return res