Anonymous committed 6f3830c

codeassist: added ignore_unknown parameter to get_calltip()

Comments (0)

Files changed (2)


     return PyDocExtractor().get_doc(pyobject)
-def get_calltip(project, source_code, offset, resource=None, maxfixes=1):
+def get_calltip(project, source_code, offset, resource=None,
+                maxfixes=1, ignore_unknown=False):
     """Get the calltip of a function
     The format of the returned string is
         offset = source_code.rindex('(', 0, offset) - 1
     to handle simple situations.
+    If `ignore_unknown` is `True`, `None` is returned for functions
+    without source-code like builtins and extensions.
     pyname = _find_pyname_at(project, source_code, offset, resource, maxfixes)
     if pyname is None:
         return None
     pyobject = pyname.get_object()
-    return PyDocExtractor().get_calltip(pyobject)
+    return PyDocExtractor().get_calltip(pyobject, ignore_unknown)
 def get_definition_location(project, source_code, offset,
             return self._trim_docstring(pyobject.get_doc())
         return None
-    def get_calltip(self, pyobject):
+    def get_calltip(self, pyobject, ignore_unknown=False):
             if isinstance(pyobject, pyobjects.AbstractClass):
                 pyobject = pyobject['__init__'].get_object()
                 pyobject = pyobject['__call__'].get_object()
         except exceptions.AttributeNotFoundError:
             return None
+        if ignore_unknown and not isinstance(pyobject, pyobjects.PyFunction):
+            return
         if isinstance(pyobject, pyobjects.AbstractFunction):
             return self._get_function_signature(pyobject, add_module=True)


         doc = get_calltip(self.project, src, src.rindex('c'), mod)
         self.assertEquals('mod.C.__call__(self, p)', doc)
+    def test_get_calltips_and_including_module_name(self):
+        src = 'range()\n'
+        doc = get_calltip(self.project, src, 1, ignore_unknown=True)
+        self.assertTrue(doc is None)
 class CodeAssistInProjectsTest(unittest.TestCase):