lenskit.lazy#
Types and functions for lazy values. These are used mostly for pipeline inputs.
Classes#
Type for lazily-computed values. |
Functions#
|
Create a lazy wrapper for an already-computed value. |
|
Create a lazy value that calls the provided function to get the value as |
Module Contents#
- class lenskit.lazy.Lazy[T]#
Bases:
ProtocolType for lazily-computed values.
This is frequently used in pipeline components. If a pipeline component may or may not need one of its inputs, declare the type with this to only run it as needed:
def my_component(input: str, backup: Lazy[str]) -> str: if input == 'invalid': return backup.get() else: return input
- Stability:
- Caller (see Stability Levels).
- get()#
Get the value behind this lazy instance.
Note
When used as a pipeline input this method invokes upstream components if they have not yet been run. Therefore, it may fail if one of the required components fails or pipeline data checks fail.
- Raises:
Exception – Exceptions raised by sources of the lazy data (e.g. a thunk, or upstream components) may be raised when this method is called.
SkipComponent –
Internal exception raised to indicate that no value is available and the calling component should be skipped. Components generally do not need to handle this directly, as it is used to signal the pipeline runner.
Only raised when used as a pipeline input.
- Return type:
T