[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

`async def` breaks encapsulation?

On 24/03/20 7:25 am, Marco Sulla wrote:
> But what if you don't need `await`?
> A coroutine call `mycoro()` could act as the actual `await mycoro()`.
> If you really want `mycoro()` actual behavior, you could write `async
> mycoro()`.

The way async/await is implemented, it's not feasible to wait
until runtime to decide whether a given call should be treated
as an await or not. Different bytecode is generated for it,
and the behaviour of the enclosing function is quite different
right from the start, before the await is even reached.

Other implementation strategies are possible that would
enable "async" and "await" to be eliminated. But there are
many people, including Guido, who regard the need for these
as a feature rather than a bug, because they mark the
places where suspensions can occur. So you would have to
convince those people that these keywords *should* be
eliminated, before thinking about how to achieve it.