Commits

Joe Amenta committed 381fa83

Fixing an issue where the import fixer would improperly fix attributes
that happened to share the same name as an imported module

Comments (0)

Files changed (2)

lib3to2/fixes/fix_imports.py

         elif name_import or from_import:
             self.fix_simple_name(name)
         elif name and not attr:
-            if does_tree_import(None, MAPPING[name.value], node):
+            if does_tree_import(None, MAPPING[name.value], node) and \
+               is_probably_builtin(name):
                 self.fix_simple_name(name)
         elif name and attr:
             # Note that this will fix a dotted name that was never imported.  This will probably not matter.

lib3to2/tests/test_imports.py

         import __builtin__
         hasattr(__builtin__, "quit")"""
         self.check(b, a)
+
+    def test_no_attribute(self):
+        b = """
+        import collections
+        import queue
+
+        MyTuple = collections.namedtuple('MyTuple', ['queue', 'queue1'])
+
+        tuple_instance = MyTuple(queue.Queue(), queue.Queue())
+
+        tuple_instance.queue.put(1)
+        tuple_instance.queue1.put(1)"""
+
+        a = """
+        import collections
+        import Queue
+
+        MyTuple = collections.namedtuple('MyTuple', ['queue', 'queue1'])
+
+        tuple_instance = MyTuple(Queue.Queue(), Queue.Queue())
+
+        tuple_instance.queue.put(1)
+        tuple_instance.queue1.put(1)"""
+        self.check(b, a)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.