[Python-Dev] API design: where to add async variants of existing stdlib APIs?

Yury Selivanov yselivanov.ml at gmail.com
Wed Mar 1 10:34:04 EST 2017



On 2017-03-01 12:42 AM, Nick Coghlan wrote:
> Short version:
>
> - there are some reasonable requests for async variants of contextlib APIs
> for 3.7
> - prompted by Raymond, I'm thinking it actually makes more sense to add
> these in a new `asyncio.contextlib` module than it does to add them
> directly to the existing module
> - would anyone object strongly to my asking authors of the affected PRs to
> take their changes in that direction?

Both asynccontextmanager and AsyncExitStack do not require asyncio is 
their implementations.  Using asyncio as a helper to write tests is 
totally OK.  For example, I use asyncio to test asynchronous generators 
(PEP 525).

async/await is a generic language feature; asyncio is a framework that 
uses it.  Things like asynccontextmanager are framework agnostic, they 
can be used in programs built with asyncio, Twisted, Tornado, etc.

+1 to put both in contextlib.

Yury


More information about the Python-Dev mailing list