
On Tue, 13 Jun 2023 at 07:33, Dom Grigonis <dom.grigonis@gmail.com> wrote:
I was wandering if there are any issues in making `yield` usage to be the same as that of `await`
Most importantly: l.append(yield Object())
You should be able to use that, since yield *is* an expression. The only oddity is, you have to parenthesize the yield expression again even though it's inside parentheses: l.append((yield Object()))
Nice to have: yield with Object(): yield for i in Object():
These, though, are unlikely to be supported, since "yield <expression>" isn't going to support statements.
Also, could anyone point me in the direction, where it is explained why new await/async syntax was introduced instead of making use of already existing yield coroutine functionality?
I don't know if there's a full explanation written down, but one important reason is that you can refactor async functions without worrying about suddenly changing their behaviour unintentionally. If you happen to refactor out the last "yield" from a generator, suddenly it's not a generator any more, and you'll have a weird time trying to figure out what happened; but an async function is an async function even if it doesn't (currently) have any await points in it. Another reason is that you can have asynchronous generator functions, which use both await AND yield. It's not easy to create a two-layer yielding system on top of yield alone. ChrisA