diff options
author | Brett Cannon <brett@python.org> | 2016-04-08 19:15:27 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2016-04-08 19:15:27 (GMT) |
commit | 9e080e0e741dd70cf86500f848eee19cf8b29efa (patch) | |
tree | 7d5a4fa6c9279df0c3c3bddd2d041619a6862fa7 /Doc/library | |
parent | c5b5ba9bdafaf2542ac2e6939f025a01a10549c2 (diff) | |
download | cpython-9e080e0e741dd70cf86500f848eee19cf8b29efa.zip cpython-9e080e0e741dd70cf86500f848eee19cf8b29efa.tar.gz cpython-9e080e0e741dd70cf86500f848eee19cf8b29efa.tar.bz2 |
Issue #25609: Introduce contextlib.AbstractContextManager and
typing.ContextManager.
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/contextlib.rst | 16 | ||||
-rw-r--r-- | Doc/library/typing.rst | 12 |
2 files changed, 23 insertions, 5 deletions
diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst index c112241..7876e7a 100644 --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -18,6 +18,18 @@ Utilities Functions and classes provided: +.. class:: AbstractContextManager + + An abstract base class for classes that implement + :meth:`object.__enter__` and :meth:`object.__exit__`. A default + implementation for :meth:`object.__enter__` is provided which returns + ``self`` while :meth:`object.__exit__` is an abstract method which by default + returns ``None``. See also the definition of :ref:`typecontextmanager`. + + .. versionadded:: 3.6 + + + .. decorator:: contextmanager This function is a :term:`decorator` that can be used to define a factory @@ -447,9 +459,9 @@ Here's an example of doing this for a context manager that accepts resource acquisition and release functions, along with an optional validation function, and maps them to the context management protocol:: - from contextlib import contextmanager, ExitStack + from contextlib import contextmanager, AbstractContextManager, ExitStack - class ResourceManager: + class ResourceManager(AbstractContextManager): def __init__(self, acquire_resource, release_resource, check_resource_ok=None): self.acquire_resource = acquire_resource diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 1bd4b09..f609a51 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -345,15 +345,15 @@ The module defines the following classes, functions and decorators: .. class:: Iterable(Generic[T_co]) - A generic version of the :class:`collections.abc.Iterable`. + A generic version of :class:`collections.abc.Iterable`. .. class:: Iterator(Iterable[T_co]) - A generic version of the :class:`collections.abc.Iterator`. + A generic version of :class:`collections.abc.Iterator`. .. class:: Reversible(Iterable[T_co]) - A generic version of the :class:`collections.abc.Reversible`. + A generic version of :class:`collections.abc.Reversible`. .. class:: SupportsInt @@ -448,6 +448,12 @@ The module defines the following classes, functions and decorators: A generic version of :class:`collections.abc.ValuesView`. +.. class:: ContextManager(Generic[T_co]) + + A generic version of :class:`contextlib.AbstractContextManager`. + + .. versionadded:: 3.6 + .. class:: Dict(dict, MutableMapping[KT, VT]) A generic version of :class:`dict`. |