README.rst 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. =============
  2. ABC-Backports
  3. =============
  4. Usage:
  5. .. code-block:: python
  6. try:
  7. # ABCs live in "collections.abc" in Python >= 3.3
  8. from collections.abc import Coroutine, Generator
  9. except ImportError:
  10. # fall back to import from "backports_abc"
  11. from backports_abc import Coroutine, Generator
  12. You can also install the ABCs into the stdlib by calling the ``patch()``
  13. function:
  14. .. code-block:: python
  15. import backports_abc
  16. backports_abc.patch()
  17. try:
  18. # ABCs live in "collections.abc" in Python >= 3.3
  19. from collections.abc import Coroutine, Generator
  20. except ImportError:
  21. # fall back to import from "collections" in Python <= 3.2
  22. from backports_abc import Coroutine, Generator
  23. Currently, ``patch()`` provides the following names if missing:
  24. * ``collections.abc.Generator``
  25. * ``collections.abc.Awaitable``
  26. * ``collections.abc.Coroutine``
  27. * ``inspect.isawaitable(obj)``
  28. All of them are also available directly from the ``backports_abc``
  29. module namespace.
  30. In Python 2.x and Python 3.2, it patches the ``collections`` module
  31. instead of the ``collections.abc`` module. Any names that are already
  32. available when importing this module will not be overwritten.
  33. The names that were previously patched by ``patch()`` can be queried
  34. through the mapping in ``backports_abc.PATCHED``.