[Python-Dev] Importance of "async" keyword

Sven R. Kunze srkunze at mail.de
Wed Jun 24 23:21:54 CEST 2015


Thanks, Yury, for you quick response.

On 24.06.2015 22:16, Yury Selivanov wrote:
> Sven, if we don't have 'async def', and instead say that "a function 
> is a *coroutine function* when it has at least one 'await' 
> expression", then when you refactor "useful()" by removing the "await" 
> from it, it stops being a *coroutine function*, which means that it 
> won't return an *awaitable* anymore.  Hence the "await useful()" call 
> in the "important()" function will be broken.

I feared you would say that. Your reasoning assumes that *await* needs 
an *explicitly declared awaitable*.

Let us assume for a moment, we had no async keyword. So, any awaitable 
needs to have at least 1 await in it. Why can we not have awaitables 
with 0 awaits in them?

>
> 'async def' guarantees that function always return a "coroutine"; it 
> eliminates the need of using @asyncio.coroutine decorator (or 
> similar), which besides making code easier to read, also improves the 
> performance.  Not to mention new 'async for' and 'async with' statements.

Recently, I read Guido's blog about the history of Python and how he 
eliminated special cases from Python step by step. As I see it, the same 
could be done here.

What is the difference of a function (no awaits) or an awaitable (> 1 
awaits) from an end-user's perspective (i.e. the programmer)?

My answer would be: none. When used the same way, they should behave in 
the same manner. As long as, we get our nice tracebacks when something 
went wrong, everything seems find to me.


Please, correct me if I am wrong.

>
> This is also covered in the rationale section of the PEP [2]
>
> [1] https://www.python.org/dev/peps/pep-0492/#importance-of-async-keyword
> [2] https://www.python.org/dev/peps/pep-0492/#rationale-and-goals
>
> Thanks,
> Yury
>
> P.S. This and many other things were discussed at length on the 
> mailing lists, I suggest you to browse through the archives.

I can imagine that. As said I went through of some of them, but it could 
be that I missed some of them as well.

Is there a way to search them through (by not using Google)?


Regard,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150624/b2a6addf/attachment.html>


More information about the Python-Dev mailing list