bpo-38415: Allow using @asynccontextmanager-made ctx managers as decorators (GH-16667)

This commit is contained in:
Jason Fried 2021-09-23 14:36:03 -07:00 committed by GitHub
parent af90b5498b
commit 86b833badd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 87 additions and 0 deletions

View file

@ -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