diff options
Diffstat (limited to 'Demo')
-rw-r--r-- | Demo/parser/test_unparse.py | 16 | ||||
-rw-r--r-- | Demo/parser/unparse.py | 12 |
2 files changed, 23 insertions, 5 deletions
diff --git a/Demo/parser/test_unparse.py b/Demo/parser/test_unparse.py index 7d85f16..3a795e9 100644 --- a/Demo/parser/test_unparse.py +++ b/Demo/parser/test_unparse.py @@ -80,7 +80,18 @@ elif cond2: suite2 """ - +try_except_finally = """\ +try: + suite1 +except ex1: + suite2 +except ex2: + suite3 +else: + suite4 +finally: + suite5 +""" class ASTTestCase(unittest.TestCase): def assertASTEqual(self, ast1, ast2): @@ -181,6 +192,9 @@ class UnparseTestCase(ASTTestCase): self.check_roundtrip(elif1) self.check_roundtrip(elif2) + def test_try_except_finally(self): + self.check_roundtrip(try_except_finally) + class DirectoryTestCase(ASTTestCase): """Test roundtrip behaviour on all files in Lib and Lib/test.""" diff --git a/Demo/parser/unparse.py b/Demo/parser/unparse.py index 03dd9e1..fa8f434 100644 --- a/Demo/parser/unparse.py +++ b/Demo/parser/unparse.py @@ -169,10 +169,14 @@ class Unparser: self.leave() def _TryFinally(self, t): - self.fill("try") - self.enter() - self.dispatch(t.body) - self.leave() + if len(t.body) == 1 and isinstance(t.body[0], ast.TryExcept): + # try-except-finally + self.dispatch(t.body) + else: + self.fill("try") + self.enter() + self.dispatch(t.body) + self.leave() self.fill("finally") self.enter() |