This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author uburuntu
Recipients uburuntu
Date 2020-07-02.18:22:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1593714173.91.0.0149218020987.issue41197@roundup.psfhosted.org>
In-reply-to
Content
# Async magic methods in contextlib.closing

I think `__aenter__` and `__aexit__` methods should be added to `contextlib.closing`, so that we can use `contextlib.closing` in async code too.

For example:

```python3
class SomeAPI:
    ...

    async def request(self):
        pass

    async def close(self):
        await self.session.close()
        

async with closing(SomeAPI()) as api:
    response = await api.request()
    print(response)
```

Also these methods can be moved to another class (like `asyncclosing` along the lines of `asynccontextmanager`).
History
Date User Action Args
2020-07-02 18:22:53uburuntusetrecipients: + uburuntu
2020-07-02 18:22:53uburuntusetmessageid: <1593714173.91.0.0149218020987.issue41197@roundup.psfhosted.org>
2020-07-02 18:22:53uburuntulinkissue41197 messages
2020-07-02 18:22:53uburuntucreate