summaryrefslogtreecommitdiffstats
path: root/Lib/contextlib.py
diff options
context:
space:
mode:
authorJason Fried <fried@fb.com>2021-09-23 21:36:03 (GMT)
committerGitHub <noreply@github.com>2021-09-23 21:36:03 (GMT)
commit86b833badd3d6864868404ead2f8c7994d24f85c (patch)
tree0610a6e8c1b1ca5e527181d58d29227b749ab484 /Lib/contextlib.py
parentaf90b5498b8c6acd67b50fdad007d26dfd1c5823 (diff)
downloadcpython-86b833badd3d6864868404ead2f8c7994d24f85c.zip
cpython-86b833badd3d6864868404ead2f8c7994d24f85c.tar.gz
cpython-86b833badd3d6864868404ead2f8c7994d24f85c.tar.bz2
bpo-38415: Allow using @asynccontextmanager-made ctx managers as decorators (GH-16667)
Diffstat (limited to 'Lib/contextlib.py')
-rw-r--r--Lib/contextlib.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/contextlib.py b/Lib/contextlib.py
index 8343d7e..1384d89 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