File: tutorial.rst

package info (click to toggle)
python-outcome 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 196 kB
  • sloc: python: 335; makefile: 12
file content (31 lines) | stat: -rw-r--r-- 688 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
========
Tutorial
========

.. currentmodule:: outcome

Outcome provides a function for capturing the outcome of a Python
function call, so that it can be passed around. The basic rule is::

    result = outcome.capture(f, *args, **kwargs)
    x = result.unwrap()

is the same as::

    x = f(*args, **kwargs)

even if ``f`` raises an error.

There's also :func:`acapture`::

    result = await outcome.acapture(f, *args, **kwargs)
    x = result.unwrap()

which, like before, is the same as::

    x = await f(*args, **kwargs)

An Outcome object can only be unwrapped once. A second attempt would raise an
:class:`AlreadyUsedError`.

See the :ref:`api-reference` for the types involved.