mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-06-19 16:52:06 +08:00
b1f13418e1
old-commit-hash: e8d888c45b
13 lines
343 B
Python
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
|