[issue24017] Implemenation of the PEP 492 - Coroutines with async and await syntax

Stefan Behnel report at bugs.python.org
Thu May 28 06:18:31 CEST 2015


Stefan Behnel added the comment:

> It *is* correct, see PEP 492.  Awaitable is either a coroutine *or* an object with an __await__ method.

"coroutine", yes. But "Coroutine"? Shouldn't the Coroutine ABC then require
"__await__" to be implemented? Maybe even by inheriting from Awaitable?

> Just implement tp_await/__await__ for coroutine-like objects coming from C-API or Cython.

Sure, that's how it's done. (Specifically, Coroutine is not an
Iterable/Iterator, but its __await__() returns a thin Iterator that simply
calls into the Generator code. A bit annoying and slowish, but that's what
it takes.)

I was just wondering how Cython should compile Python code that makes use
of this decorator. The Coroutine and Generator types are separated in
Cython now, and I think that's actually the right thing to do. This
types.coroutine() decorator and special casing in CPython's code base gets
a bit in the way here.

> In general, iteration protocol is still the foundation for Future-like objects

That's not really reflected in the ABCs, is it?

----------

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


More information about the Python-bugs-list mailing list