Anonymous avatar Anonymous committed 0b81489

autoimport: not saving imported names

Comments (0)

Files changed (2)

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):

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()
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.