# HG changeset patch # User Luke Macken # Date 1331614797 25200 # Node ID 6a82cb1dbb9855d67b91dd3e874e758ae86efe70 # Parent 7e576ad85663237a1e62226e48f4db59634b4f43 #14282: fix lib2to3.fixer_util.touch_import to work with __future__ imports diff -r 7e576ad85663 -r 6a82cb1dbb98 Lib/lib2to3/fixer_util.py --- a/Lib/lib2to3/fixer_util.py Mon Mar 12 21:16:33 2012 -0400 +++ b/Lib/lib2to3/fixer_util.py Mon Mar 12 21:59:57 2012 -0700 @@ -306,14 +306,15 @@ # figure out where to insert the new import. First try to find # the first import and then skip to the last one. insert_pos = offset = 0 - for idx, node in enumerate(root.children): - if not is_import_stmt(node): - continue - for offset, node2 in enumerate(root.children[idx:]): - if not is_import_stmt(node2): - break - insert_pos = idx + offset - break + if package != '__future__': + for idx, node in enumerate(root.children): + if not is_import_stmt(node): + continue + for offset, node2 in enumerate(root.children[idx:]): + if not is_import_stmt(node2): + break + insert_pos = idx + offset + break # if there are no imports where we can insert, find the docstring. # if that also fails, we stick to the beginning of the file