Hi,

I have a 2-part question:

1) Say you have a function that returns an awaitable (but not a
coroutine object). Are there any advantages or disadvantages to
replacing this with a function for which asyncio.iscoroutinefunction()
returns True and asyncio.iscoroutine() returns True for the return
value? An advantage might be, say, additional checks that asyncio
performs.

2) If there are advantages, is there a straightforward way to
construct such a replacement? In the case I have in mind (from an open
source project), the "function" you'd be starting with is the class
constructor for an async context manager that is also awaitable. So
the class has both __aenter__ and __await__ methods.

As an example naive attempt, the following _wouldn't_ work:

    @asyncio.coroutine
    def connect():
        return AsyncConnectManager()

The reason this doesn't work is that wrapping connect() in
@asyncio.coroutine() means the return value is no longer an async
context manager (it no longer has an __aenter__ method). You have to
await to get the underlying async context manager.

Thanks,
--Chris
_______________________________________________
Async-sig mailing list
Async-sig@python.org
https://mail.python.org/mailman/listinfo/async-sig
Code of Conduct: https://www.python.org/psf/codeofconduct/

Reply via email to