mirror of
https://github.com/python/cpython.git
synced 2025-09-18 14:40:43 +00:00
Output try-except-finally statements where appropriate.
This commit is contained in:
parent
8d6d760422
commit
81ad8ccdfb
2 changed files with 23 additions and 5 deletions
|
@ -80,7 +80,18 @@ elif cond2:
|
||||||
suite2
|
suite2
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
try_except_finally = """\
|
||||||
|
try:
|
||||||
|
suite1
|
||||||
|
except ex1:
|
||||||
|
suite2
|
||||||
|
except ex2:
|
||||||
|
suite3
|
||||||
|
else:
|
||||||
|
suite4
|
||||||
|
finally:
|
||||||
|
suite5
|
||||||
|
"""
|
||||||
|
|
||||||
class ASTTestCase(unittest.TestCase):
|
class ASTTestCase(unittest.TestCase):
|
||||||
def assertASTEqual(self, ast1, ast2):
|
def assertASTEqual(self, ast1, ast2):
|
||||||
|
@ -181,6 +192,9 @@ class UnparseTestCase(ASTTestCase):
|
||||||
self.check_roundtrip(elif1)
|
self.check_roundtrip(elif1)
|
||||||
self.check_roundtrip(elif2)
|
self.check_roundtrip(elif2)
|
||||||
|
|
||||||
|
def test_try_except_finally(self):
|
||||||
|
self.check_roundtrip(try_except_finally)
|
||||||
|
|
||||||
class DirectoryTestCase(ASTTestCase):
|
class DirectoryTestCase(ASTTestCase):
|
||||||
"""Test roundtrip behaviour on all files in Lib and Lib/test."""
|
"""Test roundtrip behaviour on all files in Lib and Lib/test."""
|
||||||
|
|
||||||
|
|
|
@ -169,6 +169,10 @@ class Unparser:
|
||||||
self.leave()
|
self.leave()
|
||||||
|
|
||||||
def _TryFinally(self, t):
|
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")
|
self.fill("try")
|
||||||
self.enter()
|
self.enter()
|
||||||
self.dispatch(t.body)
|
self.dispatch(t.body)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue