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

Yury Selivanov report at bugs.python.org
Thu May 28 18:42:29 CEST 2015


Yury Selivanov added the comment:

Stefan,


I've already committed fixes for:

1. getawaitablefunc / aiternextfunc / getaiterfunc -> unaryfunc
2. strange code in tasks.py doing "coro = iter(coro)" is now removed


I've also opened a couple of new issues (with patches for a review):

1. abc.Coroutine derived from abc.Awaitable: issue 24315
2. types.coroutine() to support Cython objects: issue 24316


I'll reply to some of your messages below:

> Another question: is it ok if Cython implements and uses the "tp_as_async" slot in all Py3.x versions (3.2+)? It shouldn't hurt, [..]

I think it's totally OK, given that you can workaround the drawback you mentioned.


>> Can't your Coroutine object return itself from its __await__, and implement 
>> __next__?  Like genobject in CPython simply returns self from its __iter__.

> That was my first try, sure, and it mostly worked. It has a drawback,
> though: it's an incomplete implementation of the Iterator protocol. It's
> still (mostly) an Iterator, but not an Iterable, so it depends on how you
> use it whether you notice or not, and whether it works at all with other
> code or not. There's a test for a failing "next(coro)" in your test suite,
> for example, which would then not fail in Cython. [..]

I think if "next(cython_coro)" does not fail is acceptable.  It's not ideal, but
the purpose of Cython is to make Python code as fast as possible, so I'd try
to avoid having any kind of "thin wrappers" around Cyhton coroutines.

----------
dependencies: +Fix types.coroutine to accept objects from Cython

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


More information about the Python-bugs-list mailing list