duck.utils.lazy¶
Lazily evaluates a callable and caches its result with an LRU policy.
Module Contents¶
Classes¶
Lazily evaluates a callable and caches its result with an LRU policy. |
|
Computes the latest result of a callable. |
Data¶
API¶
- class duck.utils.lazy.Lazy(_callable: Callable, nocache: bool = False, *args, **kwargs)[source]¶
Lazily evaluates a callable and caches its result with an LRU policy.
Supports automatic delegation of most magic methods, including:
Standard dunders (len, iter, str, etc.)
Awaitable (async/await)
Context manager
Async generator
Notes:
You can set
nocache=Trueto compute live results.
Initialization
- __all_private_attrs¶
None
- __slots__¶
(‘_Lazy__callable’, ‘_Lazy__args’, ‘_Lazy__kwargs’, ‘_Lazy__result’, ‘_Lazy__nocache’, ‘_Lazy__extra…
- _global_cache: collections.OrderedDict[Tuple[Callable, Tuple, Tuple], Any]¶
‘OrderedDict(…)’
- _max_size: int¶
256
- property extra_data: dict¶
Returns the dictionary for storing extra data.
- exception duck.utils.lazy.LazyError[source]¶
Bases:
ExceptionCustom exception for Lazy evaluation errors.
Initialization
Initialize self. See help(type(self)) for accurate signature.
- class duck.utils.lazy.LiveResult(callable_: Callable, *args, **kwargs)[source]¶
Bases:
duck.utils.lazy.LazyComputes the latest result of a callable.
Initialization
- duck.utils.lazy._dunder_forward¶
[‘len’, ‘str’, ‘repr’, ‘bytes’, ‘iter’, ‘reversed’, ‘contains’, ‘__getit…
- duck.utils.lazy.skip_dunders¶
None