3 ms·
Python somehow always manages to miss the mark. The new co-routine stuff is a good example. Who can explain to me how I return more than once from the same co-r
by dkarapetyan 11y ago
Python somehow always manages to miss the mark. The new co-routine stuff is a good example. Who can explain to me how I return more than once from the same co-routine? That is what a co-routine is after all no?
- viraptor 11y agoCheck any tutorial about it or even the relevant pep. It's explained in many places. In short: def some_co(): yield 2 yield 3
- dkarapetyan 11y agoHmm, It is a SyntaxError to have yield or yield from expressions in an async function. That's what I mean when I say it misses the mark. There are now two ways of doing the same thing and one of them is more powerful than the other. Using generators I can use both `yield` and `yield from` but if I use what they're calling co-routines then I can only use `yield from`. I see no value in the new syntax. So an async function is not really a co-routine. It is a regular function that gets to use `await` and that's it. Calling it a co-routine is misleading and confusing.
- eevee 11y agoThe new coroutine stuff is really just syntactic sugar for "yield from", which has been around for a few versions now (and in turn is little more than syntactic sugar for "yield"ing repeatedly). But you don't return more than once from a coroutine. You can suspend it as often as you like, and that's what "await" does.