[docs]classLazyInit:"""Marker object that carries a PyASTNode to support lazy attribute init. Instances of this class are stored on objects to indicate that the real attribute value should be computed later from the provided AST node."""def__init__(self,node:PyASTNode)->None:self.node=node
[docs]deflazy_invoke(func:Callable):"""A decorator for lazy properties. Apply this to a @property method so its value is computed only on first access and then reused. The computed value is stored on a private attribute named `_<property_name>`. If that attribute is a `LazyInit` marker, the wrapped function will run to produce the value."""attr_name=f"_{func.__name__}"@wraps(func)defwrapper(self):try:value=getattr(self,attr_name)exceptAttributeError:returnfunc(self)ifisinstance(value,LazyInit):returnfunc(self)returnvaluereturnwrapper