Source code for aicssegmentation.util.lazy
# Lazy evaluation utils
[docs]def lazy_property(fn):
"""
Decorator: make a lazy-evaluated property
"""
attr_name = "_lazy_" + fn.__name__
@property
def _lazy_property(self):
if not hasattr(self, attr_name):
setattr(self, attr_name, fn(self))
return getattr(self, attr_name)
return _lazy_property