From 86b833badd3d6864868404ead2f8c7994d24f85c Mon Sep 17 00:00:00 2001 From: Jason Fried Date: Thu, 23 Sep 2021 14:36:03 -0700 Subject: bpo-38415: Allow using @asynccontextmanager-made ctx managers as decorators (GH-16667) --- Lib/contextlib.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'Lib/contextlib.py') diff --git a/Lib/contextlib.py b/Lib/contextlib.py index 8343d7e519..1384d8903d 100644 --- a/Lib/contextlib.py +++ b/Lib/contextlib.py @@ -191,6 +191,14 @@ class _AsyncGeneratorContextManager( ): """Helper for @asynccontextmanager decorator.""" + def __call__(self, func): + @wraps(func) + async def inner(*args, **kwds): + async with self.__class__(self.func, self.args, self.kwds): + return await func(*args, **kwds) + + return inner + async def __aenter__(self): # do not keep args and kwds alive unnecessarily # they are only needed for recreation, which is not possible anymore -- cgit v1.2.1