Anonymous avatar Anonymous committed 96c9159

builtins: holding the parent of builting classes and functions

Comments (0)

Files changed (2)

rope/base/builtins.py

         self.initial = initial
         self.attributes = None
 
+    parent = None
+
     def get_attributes(self):
         if self.attributes is None:
             self._calculate_attributes()
     def _calculate_attributes(self):
         self.attributes = {}
         if self.module is not None:
-            self.attributes = _object_attributes(self.module)
+            self.attributes = _object_attributes(self.module, self)
         self.attributes.update(self.initial)
 
     _loaded = False
         return self._module
 
 
-def _object_attributes(obj):
+def _object_attributes(obj, parent):
     attributes = {}
     for name in dir(obj):
         if name == 'None':
         child = getattr(obj, name)
         pyobject = None
         if inspect.isclass(child):
-            pyobject = BuiltinClass(child, {})
+            pyobject = BuiltinClass(child, {}, parent=parent)
         elif inspect.isroutine(child):
-            pyobject = BuiltinFunction(builtin=child)
+            pyobject = BuiltinFunction(builtin=child, parent=parent)
         else:
             pyobject = pyobjects.get_unknown()
         attributes[name] = BuiltinName(pyobject)
 
 class BuiltinClass(pyobjects.AbstractClass):
 
-    def __init__(self, builtin, attributes):
+    def __init__(self, builtin, attributes, parent=None):
         super(BuiltinClass, self).__init__()
         self.builtin = builtin
         self.initial = attributes
         self.attributes = None
+        self.parent = parent
 
     def get_attributes(self):
         if self.attributes is None:
-            self.attributes = _object_attributes(self.builtin)
+            self.attributes = _object_attributes(self.builtin, self)
             self.attributes.update(self.initial)
         return self.attributes
 
 
 class BuiltinFunction(pyobjects.AbstractFunction):
 
-    def __init__(self, returned=None, function=None, builtin=None, argnames=[]):
+    def __init__(self, returned=None, function=None, builtin=None,
+                 argnames=[], parent=None):
         super(BuiltinFunction, self).__init__()
         self.argnames = argnames
         self.returned = returned
         self.function = function
         self.builtin = builtin
+        self.parent = parent
 
     def get_returned_object(self, args):
         if self.function is not None:

rope/contrib/codeassist.py

         return result
 
     def _get_function_signature(self, pyfunction, add_module=False):
+        location = self._location(pyfunction, add_module)
         if isinstance(pyfunction, pyobjects.PyFunction):
-            prefixes = []
-            module = pyfunction.get_module()
-            if add_module:
-                prefixes.append(self._get_module(pyfunction))
-            parent = pyfunction.parent
-            while not isinstance(parent, pyobjects.AbstractModule):
-                prefixes.append(parent.get_name())
-                prefixes.append('.')
-                parent = parent.parent
             info = functionutils.DefinitionInfo.read(pyfunction)
-            return ''.join(prefixes) + info.to_string()
+            return location + info.to_string()
         else:
-            return '%s(%s)' % (pyfunction.get_name(),
+            return '%s(%s)' % (location + pyfunction.get_name(),
                                ', '.join(pyfunction.get_param_names()))
 
+    def _location(self, pyobject, add_module=False):
+        location = []
+        parent = pyobject.parent
+        while parent and not isinstance(parent, pyobjects.AbstractModule):
+            location.append(parent.get_name())
+            location.append('.')
+            parent = parent.parent
+        if add_module:
+            if isinstance(pyobject, pyobjects.PyFunction):
+                module = pyobject.get_module()
+                location.insert(0, self._get_module(pyobject))
+            if isinstance(parent, builtins.BuiltinModule):
+                location.insert(0, parent.get_name() + '.')
+        return ''.join(location)
+
     def _get_module(self, pyfunction):
         module = pyfunction.get_module()
         if module is not None:
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.