Commits

Benjamin Peterson committed 9de340b

make fix_tuple_params keep the tree valid #7253

Comments (0)

Files changed (2)

lib2to3/fixes/fix_tuple_params.py

             new_lines[0].prefix = indent
             after = start + 1
 
+        for line in new_lines:
+            line.parent = suite[0]
         suite[0].children[after:after] = new_lines
         for i in range(after+1, after+len(new_lines)+1):
             suite[0].children[i].prefix = indent

lib2to3/tests/test_fixers.py

         a = "from functools import reduce\nreduce(a, b, c)"
         self.check(b, a)
 
+    def test_bug_7253(self):
+        # fix_tuple_params was being bad and orphaning nodes in the tree.
+        b = "def x(arg): reduce(sum, [])"
+        a = "from functools import reduce\ndef x(arg): reduce(sum, [])"
+        self.check(b, a)
+
     def test_call_with_lambda(self):
         b = "reduce(lambda x, y: x + y, seq)"
         a = "from functools import reduce\nreduce(lambda x, y: x + y, seq)"