summaryrefslogtreecommitdiffstats
path: root/Tools/parser/unparse.py
diff options
context:
space:
mode:
authorMark Dickinson <mdickinson@enthought.com>2012-05-06 16:35:19 (GMT)
committerMark Dickinson <mdickinson@enthought.com>2012-05-06 16:35:19 (GMT)
commitfe8440aec00af5bc2e995aaad205efa2e693a364 (patch)
tree853a6812968c57038f4e1afdaf94b27b54d0a822 /Tools/parser/unparse.py
parent6dbca367dceda3999979bdc3cdcfdb201f40d044 (diff)
parent1b2e9444fe9eeaef971d498445ebad7fce27f0b9 (diff)
downloadcpython-fe8440aec00af5bc2e995aaad205efa2e693a364.zip
cpython-fe8440aec00af5bc2e995aaad205efa2e693a364.tar.gz
cpython-fe8440aec00af5bc2e995aaad205efa2e693a364.tar.bz2
Issue #14965: Bring Tools/parser/unparse.py up to date with the Python 3.3. Grammar.
Diffstat (limited to 'Tools/parser/unparse.py')
-rw-r--r--Tools/parser/unparse.py42
1 files changed, 23 insertions, 19 deletions
diff --git a/Tools/parser/unparse.py b/Tools/parser/unparse.py
index e96ef54..9ae5b46 100644
--- a/Tools/parser/unparse.py
+++ b/Tools/parser/unparse.py
@@ -147,6 +147,14 @@ class Unparser:
self.dispatch(t.value)
self.write(")")
+ def _YieldFrom(self, t):
+ self.write("(")
+ self.write("yield from")
+ if t.value:
+ self.write(" ")
+ self.dispatch(t.value)
+ self.write(")")
+
def _Raise(self, t):
self.fill("raise")
if not t.exc:
@@ -158,12 +166,11 @@ class Unparser:
self.write(" from ")
self.dispatch(t.cause)
- def _TryExcept(self, t):
+ def _Try(self, t):
self.fill("try")
self.enter()
self.dispatch(t.body)
self.leave()
-
for ex in t.handlers:
self.dispatch(ex)
if t.orelse:
@@ -171,22 +178,12 @@ class Unparser:
self.enter()
self.dispatch(t.orelse)
self.leave()
-
- def _TryFinally(self, t):
- if len(t.body) == 1 and isinstance(t.body[0], ast.TryExcept):
- # try-except-finally
- self.dispatch(t.body)
- else:
- self.fill("try")
+ if t.finalbody:
+ self.fill("finally")
self.enter()
- self.dispatch(t.body)
+ self.dispatch(t.finalbody)
self.leave()
- self.fill("finally")
- self.enter()
- self.dispatch(t.finalbody)
- self.leave()
-
def _ExceptHandler(self, t):
self.fill("except")
if t.type:
@@ -296,10 +293,7 @@ class Unparser:
def _With(self, t):
self.fill("with ")
- self.dispatch(t.context_expr)
- if t.optional_vars:
- self.write(" as ")
- self.dispatch(t.optional_vars)
+ interleave(lambda: self.write(", "), self.dispatch, t.items)
self.enter()
self.dispatch(t.body)
self.leave()
@@ -472,6 +466,10 @@ class Unparser:
self.dispatch(t.slice)
self.write("]")
+ def _Starred(self, t):
+ self.write("*")
+ self.dispatch(t.value)
+
# slice
def _Ellipsis(self, t):
self.write("...")
@@ -560,6 +558,12 @@ class Unparser:
if t.asname:
self.write(" as "+t.asname)
+ def _withitem(self, t):
+ self.dispatch(t.context_expr)
+ if t.optional_vars:
+ self.write(" as ")
+ self.dispatch(t.optional_vars)
+
def roundtrip(filename, output=sys.stdout):
with open(filename, "rb") as pyfile:
encoding = tokenize.detect_encoding(pyfile.readline)[0]