summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3/fixes/fix_except.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/lib2to3/fixes/fix_except.py')
-rw-r--r--Lib/lib2to3/fixes/fix_except.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/lib2to3/fixes/fix_except.py b/Lib/lib2to3/fixes/fix_except.py
index 34281a0..5d6d153 100644
--- a/Lib/lib2to3/fixes/fix_except.py
+++ b/Lib/lib2to3/fixes/fix_except.py
@@ -37,15 +37,18 @@ class FixExcept(basefix.BaseFix):
PATTERN = """
try_stmt< 'try' ':' suite
- cleanup=((except_clause ':' suite)+ ['else' ':' suite]
- ['finally' ':' suite]
- | 'finally' ':' suite) >
+ cleanup=(except_clause ':' suite)+
+ tail=(['except' ':' suite]
+ ['else' ':' suite]
+ ['finally' ':' suite]) >
"""
def transform(self, node, results):
syms = self.syms
- try_cleanup = [ch.clone() for ch in results['cleanup']]
+ tail = [n.clone() for n in results["tail"]]
+
+ try_cleanup = [ch.clone() for ch in results["cleanup"]]
for except_clause, e_suite in find_excepts(try_cleanup):
if len(except_clause.children) == 4:
(E, comma, N) = except_clause.children[1:4]
@@ -85,5 +88,5 @@ class FixExcept(basefix.BaseFix):
N.set_prefix(" ")
#TODO(cwinter) fix this when children becomes a smart list
- children = [c.clone() for c in node.children[:3]] + try_cleanup
+ children = [c.clone() for c in node.children[:3]] + try_cleanup + tail
return pytree.Node(node.type, children)