
On Mon, Sep 16, 2019 at 11:36:45AM +1200, Greg Ewing wrote:
George Fischhof wrote:
With this syntax the use / programmer do not have to write async def, nor await, because after the yield the await should come automatically.
I don't see how you can eliminate the await in your example generator. Can you show us how it would look in its entirety under your proposal?
I think the proposal is for two things: 1. `async yield i` to be syntactic sugar for `yield i; await asyncio.sleep(delay)`. 2. The interpreter should infer that a plain `def` function is actually an `async def` from the presence of `async yield`, similar to the way the interpreter infers that a plain `def` function is actually a generator from the presence of a `yield`. # Original async def ticker(delay, to): """Yield numbers from 0 to to every delay seconds.""" for i in range(to): yield i await asyncio.sleep(delay) # Re-written def ticker(delay, to): """Yield numbers from 0 to to every delay seconds.""" for i in range(to): async yield i So you save one line and perhaps 25-30 key presses when writing the function, at the cost of making it much less clear what's going on when reading the function. How does it known how long to sleep? What if you're not using asyncio, but some other framework? -- Steven