`async def` breaks encapsulation?

Marco Sulla Marco.Sulla.Python at gmail.com
Mon Mar 23 14:25:28 EDT 2020


On Tue, 17 Mar 2020 at 08:36, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>
> On 4/03/20 12:52 pm, Marco Sulla wrote:
> > Why can't an asynchronous coroutine be simply a coroutine that has an
> > `async` or an `await` in its code, without `async` in the signature?
>
> That wouldn't help as much as you seem to think. You still need
> to use 'await' whenever you call a coroutine, so switching a
> function between coroutine and non-coroutine would still have
> just as much of a ripple effect on the rest of your code.

Good point. 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()`.


More information about the Python-list mailing list