[issue38846] async: Return context manager from open(_unix)_connection
Sebastian Rittau
report at bugs.python.org
Tue Nov 19 06:54:28 EST 2019
New submission from Sebastian Rittau <srittau at rittau.biz>:
As a convenience it would be useful if async.open_connection() and open_unix_connection() would return a context manager that closes the writer on exit:
with await open_unix_connection(...) as (reader, writer):
...
This could be achieved by using a custom sub-class of tuple:
class _ConnectionContext(tuple):
def __enter__(self):
return self
def __exit__(self, *args):
self[1].close()
I can submit a PR if wanted.
----------
components: asyncio
messages: 356962
nosy: asvetlov, srittau, yselivanov
priority: normal
severity: normal
status: open
title: async: Return context manager from open(_unix)_connection
versions: Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38846>
_______________________________________
More information about the Python-bugs-list
mailing list