superleaf.operators.wrappers#
Functions
|
Wrap a function to return |
- superleaf.operators.wrappers.with_fallback(f: Callable | None = None, fallback=None, exceptions: type | tuple | str | None = <class 'Exception'>) Callable[source]#
Wrap a function to return
fallbackwhen it raises one ofexceptions.Usable directly (
with_fallback(f, 0)) or as a decorator, with or without arguments.- Parameters:
f (callable, optional) – Function to wrap. If omitted, a decorator is returned.
fallback (Any, optional) – Value returned when one of
exceptionsis raised. Default None.exceptions (type, tuple of types, or str, optional) – Exceptions to catch. Default
Exception."ignore"/"all"meanException;"raise"/"none"or None catch nothing.
- Returns:
The wrapped function, or a decorator if
fis None.- Return type:
Callable
- Raises:
ValueError – If
exceptionsis an unrecognized string.