Completed
Push — master ( 449e73...c6f33b )
by Ionel Cristian
01:09
created

src.hunter.cached_property   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 10
Duplicated Lines 0 %
Metric Value
dl 0
loc 10
rs 10
wmc 3
1
import fields
2
3
Fields = fields.factory(fields.class_sealer, initializer=False, base=object)
4
5
6
class cached_property(object):
7
    def __init__(self, func):
8
        self.func = func
9
        self.__doc__ = func.__doc__
10
11
    def __get__(self, obj, cls):
12
        if obj is None:
13
            return self
14
        value = obj.__dict__[self.func.__name__] = self.func(obj)
15
        return value
16