3333def contextmanager (
3434 func : Callable [..., AsyncGenerator [T , None ]]
3535) -> Callable [..., AsyncContextManager [T ]]:
36- """
36+ r """
3737 Create an asynchronous context manager out of an asynchronous generator function
3838
3939 This is intended as a decorator for an asynchronous generator function.
@@ -44,14 +44,17 @@ def contextmanager(
4444 .. code-block:: python3
4545
4646 @contextmanager
47- async def Context (*args, **kwargs):
47+ async def context (*args, **kwargs):
4848 # __aenter__
4949 yield # context value
5050 # __aexit__
5151
5252 Note that if an exception ends the context block, it gets re-raised at the ``yield``
5353 inside the asynchronous generator (via :py:meth:`~agen.athrow`). In order to handle
5454 this exception, the ``yield`` should be wrapped in a ``try`` statement.
55+
56+ The created context manager is a :py:class:`~.ContextDecorator` and can also be used
57+ as a decorator. It is automatically entered when a decorated function is ``await``\ ed.
5558 """
5659
5760 @wraps (func )
@@ -70,7 +73,7 @@ class ContextDecorator(AsyncContextManager[T]):
7073
7174 .. code:: python3
7275
73- class DecoratorAndContext(AsyncContextDecorator ):
76+ class DecoratorAndContext(ContextDecorator ):
7477 async def __aenter__(self) -> Any:
7578 print("entering", self)
7679
@@ -85,8 +88,8 @@ async def func():
8588
8689 Since functions are decorated with an existing context manager instance,
8790 the same instance is entered and exited on every call. If the context is
88- not safe to be entered multiple times or even concurrently the subclass
89- should implement the method `_recreate_cm(:Self) -> Self` to create a copy.
91+ not safe to be entered multiple times or even concurrently it should implement
92+ the method `` _recreate_cm(:Self) -> Self`` to create a copy of itself .
9093 """
9194
9295 __slots__ = ()
0 commit comments