Commits

Anonymous committed 0b81489

autoimport: not saving imported names

  • Participants
  • Parent commits bd4496e

Comments (0)

Files changed (2)

File rope/contrib/autoimport.py

+from rope.base import exceptions, pynames
 from rope.refactor import importutils
-from rope.base import exceptions
 
 
 class AutoImport(object):
 
     def _add_names(self, pymodule, modname):
         # XXX: exclude imported names
-        globals = [x for x in pymodule._get_structural_attributes()]
+        globals = []
+        for name, pyname in pymodule._get_structural_attributes().items():
+            if isinstance(pyname, (pynames.AssignedName, pynames.DefinedName)):
+                globals.append(name)
         self.names[modname] = globals
 
     def update_module(self, modname):

File ropetest/contrib/autoimporttest.py

         self.importer.update_resource(self.mod1)
         self.assertEquals([], self.importer.get_imports('myva'))
 
+    def test_excluding_imported_names(self):
+        self.mod1.write('import pkg\n')
+        self.importer.update_resource(self.mod1)
+        self.assertEquals([], self.importer.get_imports('pkg'))
+
 
 if __name__ == '__main__':
     unittest.main()