[Python-ideas] PEP 525: Asynchronous Generators

Adam Bartoš drekin at gmail.com
Tue Aug 9 10:18:27 EDT 2016


Hello,

when I was reading the PEP, it surprised me that return is not allowed in
an async generator. You can transparently decompose an ordinary function,
and yield from was added to be able to do the same with generators, so it
seems natural to be able to decompose async generators the same way – using
(await) yield from and return.

I found the explanation in the section about async yield from, but maybe a
link to that section might be added as explanation why return produces a
SyntaxError.

In ideal world it seems that the transition from ordinary functions to
generators and the transition from ordinary functions to async functions
(coroutines) are orthogonal, and async gnerators are the natural
combination of both transitions. I thing this is true despite the fact that
async functions are *implemented* on top of generators. I imagine the
situation as follows: being a generator adds an additional output channel –
the one leading to generator consumer, and being an async function adds an
additional output channel for communication with the scheduler. An async
generator somehow adds both these channels.

I understand that having the concepts truly ortogonal would mean tons of
work, I just think it's pity that something natural doesn't work only
because of implementation reasons. However, introducing async generators is
an important step in the right way. Thank you for that.

Regards, Adam Bartoš
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160809/c560b5ce/attachment.html>


More information about the Python-ideas mailing list