[issue46818] Proper way to inherit from collections.abc.Coroutine

Andrew Svetlov report at bugs.python.org
Tue Feb 22 06:27:13 EST 2022


Andrew Svetlov <andrew.svetlov at gmail.com> added the comment:

> Are you suggesting that I need to just inherit from Awaitable? 

Yes. Awaitable is a very base protocol, Coroutine is an implementation.

`__await__` returns a generator that is used by Python internals as if `yield from awaitable.__await__()` was called.  asyncio never sends data back to the generator but other async frameworks can do it.

`send()`/`close()`/`throw()` coroutine methods are never used now IFAIK.  The current implementation calls these methods at the C level without using Python-exposed names. Performance matters.
These methods can be still used in very rare cases, e.g. when explicit Python `yield from custom_coro.__await__()` is used.

----------
components: +Interpreter Core -asyncio

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46818>
_______________________________________


More information about the Python-bugs-list mailing list