duck.utils.lazy

Lazily evaluates a callable and caches its result with an LRU policy.

Module Contents

Classes

Lazy

Lazily evaluates a callable and caches its result with an LRU policy.

LiveResult

Computes the latest result of a callable.

Data

_dunder_forward

skip_dunders

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=True to compute live results.

Initialization

async __aenter__()[source]
async __aexit__(exc_type, exc_val, exc_tb)[source]
__aiter__()[source]
__all_private_attrs

None

async __anext__()[source]
__await__()[source]
__bool__()[source]
__call__(*args, **kwargs)[source]
__enter__()[source]
__exit__(exc_type, exc_val, exc_tb)[source]
__getattribute__(key)[source]
__setattr__(key, value)[source]
__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.

getresult() Any[source]
exception duck.utils.lazy.LazyError[source]

Bases: Exception

Custom 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.Lazy

Computes 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