Anonymous committed 6d2d202

builtins: handling "builtin unknowns", such as sys.stdout

Comments (0)

Files changed (2)


     def get_doc(self):
         if self.builtin:
-            return self.builtin.__doc__
+            return getattr(self.builtin, '__doc__', None)
     def get_name(self):
         if self.builtin:
-            return self.builtin.__name__
+            return getattr(self.builtin, '__name__', None)
     def parent(self):
         return self.argnames
+class BuiltinUnknown(_BuiltinElement, pyobjects.PyObject):
+    def __init__(self, builtin):
+        super(BuiltinUnknown, self).__init__(pyobjects.get_unknown())
+        self.builtin = builtin
+        self.type = pyobjects.get_unknown()
+    @utils.saveit
+    def get_attributes(self):
+        return _object_attributes(self.builtin, self)
 def _object_attributes(obj, parent):
     attributes = {}
     for name in dir(obj):
         elif inspect.isroutine(child):
             pyobject = BuiltinFunction(builtin=child, parent=parent)
-            pyobject = pyobjects.get_unknown()
+            pyobject = BuiltinUnknown(builtin=child)
         attributes[name] = BuiltinName(pyobject)
     return attributes


         result = self._assist(code)
         self.assert_completion_in_result('zip', 'builtin', result)
+    def test_builtin_instances(self):
+        # ``import_dynload_stdmods`` pref is disabled for test project.
+        # we need to have it enabled to make pycore._find_module()
+        # load ``sys`` module.
+        self.project.prefs['import_dynload_stdmods'] = True
+        code = 'from sys import stdout\nstdout.wr'
+        result = self._assist(code)
+        self.assert_completion_in_result('write', 'builtin', result)
+        self.assert_completion_in_result('writelines', 'builtin', result)
     def test_including_keywords(self):
         code = 'fo'
         result = self._assist(code)
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
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.