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

Kristiyan Kanchev report at bugs.python.org
Mon Feb 21 12:23:06 EST 2022


Kristiyan Kanchev <skrechy at tutanota.com> added the comment:

Hello Andrew, 

I'm sorry for using the bug tracker, but I wasn't sure whether posting on StackOverflow (is this the appropriate Q&A site?) will attract the attention of the right people.

Although I see you marked this as Closed, I'll be very pleased if you'd elaborate on why I don't need send/throw/close methods since they are "mandatory" from collections.abc.Coroutine. Are you suggesting that I need to just inherit from Awaitable? 

As a matter of fact, I'm writing in the bug tracker because I think that there is a potential for a change -- maybe just in the documentation. I struggle to find an example on how to implement a Coroutine class, and I believe this will be valuable to others, too. While reading the documentation of collections.abc.Coroutine one have an impression that he/she would have to return an Iterator from __await__() and then outer coroutines will call send/throw/close methods of the derived collections.abc.Coroutine class, but this is not the case. One have to dive deep into Python internals to grasp why Iterator should be returned and how outer coroutines interact with it.

Moreover, there are several cross-referencing PEPs that explain yield, yield from, await but none of them has an example of how to construct a Coroutine from a class. Explanation and examples are always concerned with `yield` and its suspension property is presented as implementation detail.

----------

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


More information about the Python-bugs-list mailing list