API Reference¶
- outcome.capture(sync_fn, *args, **kwargs)¶
Run
sync_fn(*args, **kwargs)and capture the result.
- await outcome.acapture(async_fn, *args, **kwargs)¶
Run
await async_fn(*args, **kwargs)and capture the result.
- class outcome.Outcome¶
An abstract class representing the result of a Python computation.
This class has two concrete subclasses:
Valuerepresenting a value, andErrorrepresenting an exception.In addition to the methods described below, comparison operators on
ValueandErrorobjects (==,<, etc.) check that the other object is also aValueorErrorobject respectively, and then compare the contained objects.Outcomeobjects are hashable if the contained objects are hashable.- abstractmethod await asend(agen)¶
Send or throw the contained value or exception into the given async generator object.
- Parameters:
agen – An async generator object supporting
.asend()and.athrow()methods.
- abstractmethod send(gen)¶
Send or throw the contained value or exception into the given generator object.
- Parameters:
gen – A generator object supporting
.send()and.throw()methods.
- abstractmethod unwrap()¶
Return or raise the contained value or exception.
These two lines of code are equivalent:
x = fn(*args) x = outcome.capture(fn, *args).unwrap()
- class outcome.Value(value)¶
Concrete
Outcomesubclass representing a regular value.- await asend(agen)¶
Send or throw the contained value or exception into the given async generator object.
- Parameters:
agen – An async generator object supporting
.asend()and.athrow()methods.
- send(gen)¶
Send or throw the contained value or exception into the given generator object.
- Parameters:
gen – A generator object supporting
.send()and.throw()methods.
- unwrap()¶
Return or raise the contained value or exception.
These two lines of code are equivalent:
x = fn(*args) x = outcome.capture(fn, *args).unwrap()
- class outcome.Error(error)¶
Concrete
Outcomesubclass representing a raised exception.- await asend(agen)¶
Send or throw the contained value or exception into the given async generator object.
- Parameters:
agen – An async generator object supporting
.asend()and.athrow()methods.
- send(it)¶
Send or throw the contained value or exception into the given generator object.
- Parameters:
gen – A generator object supporting
.send()and.throw()methods.
- unwrap()¶
Return or raise the contained value or exception.
These two lines of code are equivalent:
x = fn(*args) x = outcome.capture(fn, *args).unwrap()
- class outcome.AlreadyUsedError¶
An Outcome can only be unwrapped once.