MCPcopy Create free account
hub / github.com/dabeaz/python-cookbook / __get__

Method __get__

src/8/lazily_computed_attributes/example1.py:4–10  ·  view source on GitHub ↗
(self, instance, cls)

Source from the content-addressed store, hash-verified

2 def __init__(self, func):
3 self.func = func
4 def __get__(self, instance, cls):
5 if instance is None:
6 return self
7 else:
8 value = self.func(instance)
9 setattr(instance, self.func.__name__, value)
10 return value
11
12if __name__ == '__main__':
13 import math

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected