Index: lib2to3/fixes/fix_imports.py =================================================================== --- lib2to3/fixes/fix_imports.py (revision 68503) +++ lib2to3/fixes/fix_imports.py (working copy) @@ -72,9 +72,9 @@ ( any | import_as_name< any 'as' any > | import_as_names< any* >) [')'] > """ % mod_list - yield """import_name< 'import' (dotted_as_name< (%s) 'as' any > | + yield """import_name< 'import' (dotted_as_name< (%s) 'as' as_what=any > | multiple_imports=dotted_as_names< - any* dotted_as_name< (%s) 'as' any > any* >) > + any* dotted_as_name< (%s) 'as' as_what=any > any* >) > """ % (mod_list, mod_list) # Find usages of module members in code e.g. thread.foo(bar) @@ -117,6 +117,7 @@ def start_tree(self, tree, filename): super(FixImports, self).start_tree(tree, filename) self.replace = {} + self.seen_cstringio = False def transform(self, node, results): import_mod = results.get("module_name") @@ -127,7 +128,12 @@ if "name_import" in results: # If it's not a "from x import x, y" or "import x as y" import, # marked its usage to be replaced. - self.replace[mod_name] = new_name + if not (mod_name == "StringIO" and self.seen_cstringio): + self.replace[mod_name] = new_name + elif not self.seen_cstringio and mod_name == "cStringIO": + as_what = results.get("as_what") + if as_what is not None and as_what.value == "StringIO": + self.seen_cstringio = True if "multiple_imports" in results: # This is a nasty hack to fix multiple imports on a # line (e.g., "import StringIO, urlparse"). The problem is that I