Anonymous avatar Anonymous committed a52f796

builtins: returning builtins when don't know the module

Comments (0)

Files changed (1)

rope/base/builtins.py

         return self._module
 
 
+class _BuiltinElement(object):
+
+    def __init__(self, builtin, parent=None):
+        self.builtin = builtin
+        self._parent = parent
+
+    def get_doc(self):
+        if self.builtin:
+            return self.builtin.__doc__
+
+    def get_name(self):
+        if self.builtin:
+            return self.builtin.__name__
+
+    @property
+    def parent(self):
+        if self._parent is None:
+            return builtins
+        return self._parent
+
+
+class BuiltinClass(_BuiltinElement, pyobjects.AbstractClass):
+
+    def __init__(self, builtin, attributes, parent=None):
+        _BuiltinElement.__init__(self, builtin, parent)
+        pyobjects.AbstractClass.__init__(self)
+        self.initial = attributes
+        self.attributes = None
+
+    def get_attributes(self):
+        if self.attributes is None:
+            self.attributes = _object_attributes(self.builtin, self)
+            self.attributes.update(self.initial)
+        return self.attributes
+
+
+class BuiltinFunction(_BuiltinElement, pyobjects.AbstractFunction):
+
+    def __init__(self, returned=None, function=None, builtin=None,
+                 argnames=[], parent=None):
+        _BuiltinElement.__init__(self, builtin, parent)
+        pyobjects.AbstractFunction.__init__(self)
+        self.argnames = argnames
+        self.returned = returned
+        self.function = function
+
+    def get_returned_object(self, args):
+        if self.function is not None:
+            return self.function(_CallContext(self.argnames, args))
+        else:
+            return self.returned
+
+    def get_param_names(self):
+        return self.argnames
+
+
 def _object_attributes(obj, parent):
     attributes = {}
     for name in dir(obj):
         attributes[name] = BuiltinName(pyobject)
     return attributes
 
-class BuiltinClass(pyobjects.AbstractClass):
-
-    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)
-            self.attributes.update(self.initial)
-        return self.attributes
-
-    def get_doc(self):
-        return self.builtin.__doc__
-
-    def get_name(self):
-        return self.builtin.__name__
-
-
-class BuiltinFunction(pyobjects.AbstractFunction):
-
-    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:
-            return self.function(_CallContext(self.argnames, args))
-        else:
-            return self.returned
-
-    def get_doc(self):
-        if self.builtin:
-            return self.builtin.__doc__
-
-    def get_name(self):
-        if self.builtin:
-            return self.builtin.__name__
-
-    def get_param_names(self):
-        return self.argnames
-
 
 def _create_builtin_type_getter(cls):
     def _get_builtin(*args):
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.