Anonymous avatar Anonymous committed b2dfb28

builtins: calculating builtin class attributes

Comments (0)

Files changed (1)

rope/base/builtins.py

 
     def _calculate_attributes(self):
         self.attributes = {}
-        if self.module is None:
-            return
-        for name in dir(self.module):
-            if name in self.initial or name == 'None':
-                continue
-            obj = getattr(self.module, name)
-            pyobject = None
-            if inspect.isclass(obj):
-                pyobject = BuiltinClass(obj, {})
-            elif inspect.isroutine(obj):
-                pyobject = BuiltinFunction(builtin=obj)
-            else:
-                pyobject = pyobjects.get_unknown()
-            self.attributes[name] = BuiltinName(pyobject)
+        if self.module is not None:
+            self.attributes = _object_attributes(self.module)
         self.attributes.update(self.initial)
 
     _loaded = False
         return self._module
 
 
+def _object_attributes(obj):
+    attributes = {}
+    for name in dir(obj):
+        if name == 'None':
+            continue
+        child = getattr(obj, name)
+        pyobject = None
+        if inspect.isclass(child):
+            pyobject = BuiltinClass(child, {})
+        elif inspect.isroutine(child):
+            pyobject = BuiltinFunction(builtin=child)
+        else:
+            pyobject = pyobjects.get_unknown()
+        attributes[name] = BuiltinName(pyobject)
+    return attributes
+
 class BuiltinClass(pyobjects.AbstractClass):
 
     def __init__(self, builtin, attributes):
         super(BuiltinClass, self).__init__()
         self.builtin = builtin
-        self.attributes = attributes
+        self.initial = attributes
+        self.attributes = None
 
     def get_attributes(self):
+        if self.attributes is None:
+            self.attributes = _object_attributes(self.builtin)
+            self.attributes.update(self.initial)
         return self.attributes
 
     def get_doc(self):
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.