1. specialunderwear
  2. rope


Ali Gholami Rudi  committed dde1a21

autoimport: passing underlined to AutoImport.__init__()

  • Participants
  • Parent commits fb3bf5c
  • Branches trunk

Comments (0)

Files changed (2)

File rope/contrib/autoimport.py

View file
-    def __init__(self, project, observe=True):
+    def __init__(self, project, observe=True, underlined=False):
         """Construct an AutoImport object
         If `observe` is `True`, listen for project changes and update
         the cache.
+        If `underlined` is `True`, underlined names are cached, too.
         self.project = project
+        self.underlined = underlined
         self.names = project.data_files.read_data('globalnames')
         if self.names is None:
             self.names = {}
         This function tries to find modules that have a global name
         that starts with `starting`.
         # XXX: breaking if gave up! use generators
         result = []
         return result
-    def generate_cache(self, resources=None, underlined=False,
+    def generate_cache(self, resources=None, underlined=None,
         """Generate global name cache for project files
             self.update_resource(file, underlined)
-    def generate_modules_cache(self, modules, underlined=False,
+    def generate_modules_cache(self, modules, underlined=None,
         """Generate global name cache for modules listed in `modules`"""
         job_set = task_handle.create_jobset(
         lineno = code.count('\n', 0, offset) + 1
         return lineno
-    def update_resource(self, resource, underlined=False):
+    def update_resource(self, resource, underlined=None):
         """Update the cache for global names in `resource`"""
             pymodule = self.project.pycore.resource_to_pyobject(resource)
         except exceptions.ModuleSyntaxError:
-    def update_module(self, modname, underlined=False):
+    def update_module(self, modname, underlined=None):
         """Update the cache for global names in `modname` module
         `modname` is the name of a module.
         return importutils.get_module_name(self.project.pycore, resource)
     def _add_names(self, pymodule, modname, underlined):
+        if underlined is None:
+            underlined = self.underlined
         globals = []
         for name, pyname in pymodule._get_structural_attributes().items():
             if not underlined and name.startswith('_'):

File ropetest/contrib/autoimporttest.py

View file
         self.importer.update_resource(self.mod1, underlined=True)
         self.assertEquals(['mod1'], self.importer.get_modules('_myvar'))
+    def test_caching_underlined_names_passing_to_the_constructor(self):
+        importer = autoimport.AutoImport(self.project, False, True)
+        self.mod1.write('_myvar = None\n')
+        importer.update_resource(self.mod1)
+        self.assertEquals(['mod1'], importer.get_modules('_myvar'))
     def test_name_locations(self):
         self.mod1.write('myvar = None\n')