[Python-checkins] peps: pep-0492: Explain why "async def" and not "def async".
yury.selivanov
python-checkins at python.org
Thu Apr 23 20:20:47 CEST 2015
https://hg.python.org/peps/rev/8cb4c0ab0931
changeset: 5787:8cb4c0ab0931
user: Yury Selivanov <yselivanov at sprymix.com>
date: Thu Apr 23 14:20:41 2015 -0400
summary:
pep-0492: Explain why "async def" and not "def async".
files:
pep-0492.txt | 16 ++++++++++++++++
1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/pep-0492.txt b/pep-0492.txt
--- a/pep-0492.txt
+++ b/pep-0492.txt
@@ -884,6 +884,22 @@
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
---------------------------
--
Repository URL: https://hg.python.org/peps
More information about the Python-checkins
mailing list