[issue24400] Awaitable ABC incompatible with functools.singledispatch

Stefan Behnel report at bugs.python.org
Mon Jun 8 17:56:26 CEST 2015


Stefan Behnel added the comment:

I agree that the "extra bit" is a quirk. Ideally, Coroutine and Generator would share a common base class that has "send", "throw" and "close". Additionally, a Coroutine would be an Awaitable whereas a Generator is an Iterator. The internal implementation of generators and coroutines would (or at least, could) then follow by splitting them into separate types.

The tricky bridge between the two is the types.coroutine() decorator, which is intended to say "this Generator is a Coroutine", i.e. it turns a Generator into an Awaitable Generator. As the current implementation shows, however, this can also be done without the internal flag. All this needs is a wrapper, and that could be implemented in C to make it fast and even special cased to further speed it up.

In a way, the current implementation focusses on runtime optimisation, not on a clean design.

----------
nosy: +scoder

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24400>
_______________________________________


More information about the Python-bugs-list mailing list