pep-0492: Explain why "async def" and not "def async".
This commit is contained in:
parent
d5c4d8ac67
commit
d0d589154f
16
pep-0492.txt
16
pep-0492.txt
|
@ -884,6 +884,22 @@ stating that the statement is asynchronous. It is also more consistent
|
||||||
with the existing grammar.
|
with the existing grammar.
|
||||||
|
|
||||||
|
|
||||||
|
Why "async def" and not "def async"
|
||||||
|
-----------------------------------
|
||||||
|
|
||||||
|
``async`` keyword is a *statement qualifier*. A good analogy to it are
|
||||||
|
"static", "public", "unsafe" keywords from other languages. "async
|
||||||
|
for" is an asynchronous "for" statement, "async with" is an
|
||||||
|
asynchronous "with" statement, "async def" is an asynchronous function.
|
||||||
|
|
||||||
|
Having "async" after the main statement keyword might introduce some
|
||||||
|
confusion, like "for async item in iterator" can be read as "for each
|
||||||
|
asynchronous item in iterator".
|
||||||
|
|
||||||
|
Also, "async def" better separates coroutines from regular functions
|
||||||
|
visually.
|
||||||
|
|
||||||
|
|
||||||
Why not a __future__ import
|
Why not a __future__ import
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue