MCPcopy Create free account
hub / github.com/ActiveState/code / get

Function get

recipes/Python/576563_Cached_Property/recipe-576563.py:3–12  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1def cached_property(f):
2 """returns a cached property that is calculated by function f"""
3 def get(self):
4 try:
5 return self._property_cache[f]
6 except AttributeError:
7 self._property_cache = {}
8 x = self._property_cache[f] = f(self)
9 return x
10 except KeyError:
11 x = self._property_cache[f] = f(self)
12 return x
13
14 return property(get)

Callers 5

runMethod · 0.50
recipe-252132.pyFile · 0.50
recipe-52195.pyFile · 0.50
recipe-528875.pyFile · 0.50
__init__Method · 0.50

Calls 1

fFunction · 0.50

Tested by

no test coverage detected