Files
sunnypilot/common/lazy_property.py
George Hotz b1f13418e1 common folder
old-commit-hash: e8d888c45b
2020-01-17 10:28:44 -08:00

13 lines
343 B
Python

class lazy_property():
"""Defines a property whose value will be computed only once and as needed.
This can only be used on instance methods.
"""
def __init__(self, func):
self._func = func
def __get__(self, obj_self, cls):
value = self._func(obj_self)
setattr(obj_self, self._func.__name__, value)
return value