From 7493a3ebb8c9681a3165b506d0ce44f322ac269e Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 10 Apr 2014 00:17:48 -0400 Subject: teach unparse about matrix multiplication --- Tools/parser/unparse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Tools/parser/unparse.py') diff --git a/Tools/parser/unparse.py b/Tools/parser/unparse.py index 837cd81aaf..258c648b6b 100644 --- a/Tools/parser/unparse.py +++ b/Tools/parser/unparse.py @@ -401,7 +401,7 @@ class Unparser: self.dispatch(t.operand) self.write(")") - binop = { "Add":"+", "Sub":"-", "Mult":"*", "Div":"/", "Mod":"%", + binop = { "Add":"+", "Sub":"-", "Mult":"*", "MatMult":"@", "Div":"/", "Mod":"%", "LShift":"<<", "RShift":">>", "BitOr":"|", "BitXor":"^", "BitAnd":"&", "FloorDiv":"//", "Pow": "**"} def _BinOp(self, t): -- cgit v1.2.1 From 2571248c875b79a134b3a6fd4010c2a2e6e2c7aa Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 5 May 2015 20:16:41 -0400 Subject: PEP 448: additional unpacking generalizations (closes #2292) Patch by Neil Girdhar. --- Tools/parser/unparse.py | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) (limited to 'Tools/parser/unparse.py') diff --git a/Tools/parser/unparse.py b/Tools/parser/unparse.py index 258c648b6b..0c1cc5fe41 100644 --- a/Tools/parser/unparse.py +++ b/Tools/parser/unparse.py @@ -211,16 +211,6 @@ class Unparser: if comma: self.write(", ") else: comma = True self.dispatch(e) - if t.starargs: - if comma: self.write(", ") - else: comma = True - self.write("*") - self.dispatch(t.starargs) - if t.kwargs: - if comma: self.write(", ") - else: comma = True - self.write("**") - self.dispatch(t.kwargs) self.write(")") self.enter() @@ -450,16 +440,6 @@ class Unparser: if comma: self.write(", ") else: comma = True self.dispatch(e) - if t.starargs: - if comma: self.write(", ") - else: comma = True - self.write("*") - self.dispatch(t.starargs) - if t.kwargs: - if comma: self.write(", ") - else: comma = True - self.write("**") - self.dispatch(t.kwargs) self.write(")") def _Subscript(self, t): @@ -543,8 +523,11 @@ class Unparser: self.dispatch(t.kwarg.annotation) def _keyword(self, t): - self.write(t.arg) - self.write("=") + if t.arg is None: + self.write("**") + else: + self.write(t.arg) + self.write("=") self.dispatch(t.value) def _Lambda(self, t): -- cgit v1.2.1 From ea639832c36905ecb07caba111f614c4bbf9bdd6 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Mon, 11 May 2015 22:57:16 -0400 Subject: PEP 0492 -- Coroutines with async and await syntax. Issue #24017. --- Tools/parser/unparse.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'Tools/parser/unparse.py') diff --git a/Tools/parser/unparse.py b/Tools/parser/unparse.py index 0c1cc5fe41..c82857710b 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)) -- cgit v1.2.1