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.

classification
Title: async: Return context manager from open(_unix)_connection
Type: Stage: resolved
Components: asyncio Versions: Python 3.8
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, srittau, yselivanov
Priority: normal Keywords:

Created on 2019-11-19 11:54 by srittau, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg356962 - (view) Author: Sebastian Rittau (srittau) * Date: 2019-11-19 11:54
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.
msg356964 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-11-19 12:06
From my understanding, Yuri doesn't want to improve the existing streaming API but invent something blessing new.

The improvement like you proposed has a very low chance to be accepted.
History
Date User Action Args
2022-04-11 14:59:23adminsetgithub: 83027
2019-12-05 12:43:27asvetlovsetstatus: open -> closed
resolution: wont fix
stage: resolved
2019-11-19 12:06:08asvetlovsetmessages: + msg356964
2019-11-19 11:54:28srittaucreate