File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -80,7 +80,18 @@ class Foo: pass
8080 suite2
8181"""
8282
83-
83+ try_except_finally = """\
84+ try:
85+ suite1
86+ except ex1:
87+ suite2
88+ except ex2:
89+ suite3
90+ else:
91+ suite4
92+ finally:
93+ suite5
94+ """
8495
8596class ASTTestCase (unittest .TestCase ):
8697 def assertASTEqual (self , ast1 , ast2 ):
@@ -181,6 +192,9 @@ def test_elifs(self):
181192 self .check_roundtrip (elif1 )
182193 self .check_roundtrip (elif2 )
183194
195+ def test_try_except_finally (self ):
196+ self .check_roundtrip (try_except_finally )
197+
184198class DirectoryTestCase (ASTTestCase ):
185199 """Test roundtrip behaviour on all files in Lib and Lib/test."""
186200
Original file line number Diff line number Diff line change @@ -169,10 +169,14 @@ def _TryExcept(self, t):
169169 self .leave ()
170170
171171 def _TryFinally (self , t ):
172- self .fill ("try" )
173- self .enter ()
174- self .dispatch (t .body )
175- self .leave ()
172+ if len (t .body ) == 1 and isinstance (t .body [0 ], ast .TryExcept ):
173+ # try-except-finally
174+ self .dispatch (t .body )
175+ else :
176+ self .fill ("try" )
177+ self .enter ()
178+ self .dispatch (t .body )
179+ self .leave ()
176180
177181 self .fill ("finally" )
178182 self .enter ()
You can’t perform that action at this time.
0 commit comments