API Reference¶
-
outcome.
capture
(sync_fn, *args, **kwargs)¶ Run
sync_fn(*args, **kwargs)
and capture the result.Returns: Either a Value
orError
as appropriate.
-
await
outcome.
acapture
(async_fn, *args, **kwargs)¶ Run
await async_fn(*args, **kwargs)
and capture the result.Returns: Either a Value
orError
as appropriate.
-
class
outcome.
Outcome
¶ An abstract class representing the result of a Python computation.
This class has two concrete subclasses:
Value
representing a value, andError
representing an exception.In addition to the methods described below, comparison operators on
Value
andError
objects (==
,<
, etc.) check that the other object is also aValue
orError
object respectively, and then compare the contained objects.Outcome
objects 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()
-
abstractmethod await
-
class
outcome.
Value
(value)¶ Concrete
Outcome
subclass 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()
-
await
-
class
outcome.
Error
(error)¶ Concrete
Outcome
subclass 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()
-
await
-
class
outcome.
AlreadyUsedError
¶ An Outcome can only be unwrapped once.