summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-05-12 02:57:16 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-05-12 02:57:16 (GMT)
commit7544508f0245173bff5866aa1598c8f6cce1fc5f (patch)
treebf80850d9cd46fc811f04b8c2484fb50775c697d /Tools
parent4e6bf4b3da03b132b0698f30ee931a350585b117 (diff)
downloadcpython-7544508f0245173bff5866aa1598c8f6cce1fc5f.zip
cpython-7544508f0245173bff5866aa1598c8f6cce1fc5f.tar.gz
cpython-7544508f0245173bff5866aa1598c8f6cce1fc5f.tar.bz2
PEP 0492 -- Coroutines with async and await syntax. Issue #24017.
Diffstat (limited to 'Tools')
-rw-r--r--Tools/parser/unparse.py32
1 files changed, 30 insertions, 2 deletions
diff --git a/Tools/parser/unparse.py b/Tools/parser/unparse.py
index 0c1cc5f..c828577 100644
--- a/Tools/parser/unparse.py
+++ b/Tools/parser/unparse.py
@@ -138,6 +138,14 @@ class Unparser:
self.fill("nonlocal ")
interleave(lambda: self.write(", "), self.write, t.names)
+ def _Await(self, t):
+ self.write("(")
+ self.write("await")
+ if t.value:
+ self.write(" ")
+ self.dispatch(t.value)
+ self.write(")")
+
def _Yield(self, t):
self.write("(")
self.write("yield")
@@ -218,11 +226,18 @@ class Unparser:
self.leave()
def _FunctionDef(self, t):
+ self.__FunctionDef_helper(t, "def")
+
+ def _AsyncFunctionDef(self, t):
+ self.__FunctionDef_helper(t, "async def")
+
+ def __FunctionDef_helper(self, t, fill_suffix):
self.write("\n")
for deco in t.decorator_list:
self.fill("@")
self.dispatch(deco)
- self.fill("def "+t.name + "(")
+ def_str = fill_suffix+" "+t.name + "("
+ self.fill(def_str)
self.dispatch(t.args)
self.write(")")
if t.returns:
@@ -233,7 +248,13 @@ class Unparser:
self.leave()
def _For(self, t):
- self.fill("for ")
+ self.__For_helper("for ", t)
+
+ def _AsyncFor(self, t):
+ self.__For_helper("async for ", t)
+
+ def __For_helper(self, fill, t):
+ self.fill(fill)
self.dispatch(t.target)
self.write(" in ")
self.dispatch(t.iter)
@@ -287,6 +308,13 @@ class Unparser:
self.dispatch(t.body)
self.leave()
+ def _AsyncWith(self, t):
+ self.fill("async with ")
+ interleave(lambda: self.write(", "), self.dispatch, t.items)
+ self.enter()
+ self.dispatch(t.body)
+ self.leave()
+
# expr
def _Bytes(self, t):
self.write(repr(t.s))