`async def` breaks encapsulation?
Marco Sulla
mail.python.org at marco.sulla.e4ward.com
Tue Mar 3 18:52:26 EST 2020
I worked a lot with `asyncio` many years ago, when `aiohttp` was first
born. Now I'm working again with it, since a library that I need
requires it.
asyncio is much more simple to use now, but there's something that
still make me doubtful: the require of the `async` keyword for
coroutines.
When I developed the aiohttp app, many times I changed my mind and an
async function turned back to be a normal one. But in the meanwhile
I'd used it for a bunch of coroutines, that I used for a bunch of
coroutines etc... so I had to check all the affected coroutines and
remove the `async` keyword from them.
This recall me checked exceptions in Java. If you add to a Java method
messTheCode() a `throws SomeException`, and subsequently you refactor
the code so the exception is no more raised, you have to remove the
`throws SomeException` from the function signature and to all the
functions that used `messTheCode()` that decided to not handle the
exception.
(This is why I do not use checked exceptions in Java... I wrap them in
unchecked ones. Yes, I'm an heretical :-D)
The fact that puzzles me is that no additional keyword for coroutines
was needed. A coroutines was simply a function with a `yield`. If it
quacks...
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?
More information about the Python-list
mailing list