[Python-checkins] r67426 - in sandbox/trunk/2to3/lib2to3: fixes/fix_imports.py tests/test_fixers.py

benjamin.peterson python-checkins at python.org
Fri Nov 28 23:01:40 CET 2008


Author: benjamin.peterson
Date: Fri Nov 28 23:01:40 2008
New Revision: 67426

Log:
don't replace a module name if it is in the middle of a attribute lookup

This fix also stops module names from being replaced if they are not in an attribute lookup.



Modified:
   sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py
   sandbox/trunk/2to3/lib2to3/tests/test_fixers.py

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py	Fri Nov 28 23:01:40 2008
@@ -76,10 +76,7 @@
           """ % mod_list
 
     # Find usages of module members in code e.g. thread.foo(bar)
-    # We differentiate between "bare_with_attr" and "bare_name" for the benfit
-    # of the match() override in FixImports.
     yield "power< bare_with_attr=(%s) trailer<'.' any > any* >" % bare_names
-    yield "bare_name=(%s)" % bare_names
 
 
 class FixImports(fixer_base.BaseFix):
@@ -126,8 +123,7 @@
             import_mod.replace(Name(new_name, prefix=import_mod.get_prefix()))
         else:
             # Replace usage of the module.
-            bare_name = results.get("bare_with_attr") or results.get("bare_name")
-            bare_name = bare_name[0]
+            bare_name = results["bare_with_attr"][0]
             new_name = self.replace.get(bare_name.value)
             if new_name:
                 bare_name.replace(Name(new_name, prefix=bare_name.get_prefix()))

Modified: sandbox/trunk/2to3/lib2to3/tests/test_fixers.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/test_fixers.py	(original)
+++ sandbox/trunk/2to3/lib2to3/tests/test_fixers.py	Fri Nov 28 23:01:40 2008
@@ -1509,6 +1509,16 @@
                 """ % (new, new, new)
             self.check(b, a)
 
+            b = """
+                import %s
+                x.%s
+                """ % (old, old)
+            a = """
+                import %s
+                x.%s
+                """ % (new, old)
+            self.check(b, a)
+
 
 
 class Test_imports2(Test_imports):


More information about the Python-checkins mailing list