wrap

wrap

wrap(*keep)[source]

Decorates the given function, and wraps thrown exceptions into an error result

Exception types can be provided as arguments to filter the exceptions being transformed into errors.

Example

>>> @wrap(ValueError)
... def parse(s: str) -> int:
...     return int(s)
>>> parse("2")
2
>>> parse("should error")
Err1(msg="...", contexts=[])
Return type

Callable[[Callable[[TypeVar(_Parameters)], TypeVar(_ReturnType)]], Callable[[TypeVar(_Parameters)], Union[TypeVar(_ReturnType), Err]]]