aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/deprecated/python/backports-abc/README.rst
blob: 06cf94aefd98f37d9a4a7f701efd1c7c827a7e95 (plain) (blame)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
=============
ABC-Backports
=============

Usage:

.. code-block:: python

    try:
        # ABCs live in "collections.abc" in Python >= 3.3
        from collections.abc import Coroutine, Generator
    except ImportError:
        # fall back to import from "backports_abc"
        from backports_abc import Coroutine, Generator

You can also install the ABCs into the stdlib by calling the ``patch()``
function:

.. code-block:: python

    import backports_abc
    backports_abc.patch()

    try:
        # ABCs live in "collections.abc" in Python >= 3.3
        from collections.abc import Coroutine, Generator
    except ImportError:
        # fall back to import from "collections" in Python <= 3.2
        from backports_abc import Coroutine, Generator

Currently, ``patch()`` provides the following names if missing:

* ``collections.abc.Generator``
* ``collections.abc.Awaitable``
* ``collections.abc.Coroutine``
* ``inspect.isawaitable(obj)``

All of them are also available directly from the ``backports_abc``
module namespace.

In Python 2.x and Python 3.2, it patches the ``collections`` module
instead of the ``collections.abc`` module.  Any names that are already
available when importing this module will not be overwritten.

The names that were previously patched by ``patch()`` can be queried
through the mapping in ``backports_abc.PATCHED``.