Re: [Python-ideas] PEP 525: Asynchronous Generators

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š

On 2016-08-09 10:18 AM, Adam Bartoš wrote:
[..] 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.
Hi Adam, Thanks a lot for the positive feedback. Not adding 'yield from' as part of PEP 525 isn't dictated solely by the implementation difficulties. It's also important to scope the new features in such a way that we're confident that the implementation is solid, well reviewed and well tested. While I myself can see why having 'yield from' in asynchronous generators would be cool, there are many more important things and details that we have to do "right" with this PEP. Therefore my idea is to move in small steps: introduce asynchronous generators in 3.6; extend them with asynchronous 'yield from' in 3.7, if there is interest in that. Thanks, Yury
participants (2)
-
Adam Bartoš
-
Yury Selivanov