New submission from Рамзан Б. <[email protected]>:
# 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`).
----------
components: Library (Lib)
messages: 372871
nosy: Рамзан Б.
priority: normal
pull_requests: 20434
severity: normal
status: open
title: Async magic methods in contextlib.closing
type: enhancement
versions: Python 3.10, Python 3.9
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue41197>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com