Anonymous avatar Anonymous committed b8b4e6c

codeassist: added remove_self argument to get_calltip()

Comments (0)

Files changed (2)


 def get_calltip(project, source_code, offset, resource=None,
-                maxfixes=1, ignore_unknown=False):
+                maxfixes=1, ignore_unknown=False, remove_self=False):
     """Get the calltip of a function
     The format of the returned string is
     If `ignore_unknown` is `True`, `None` is returned for functions
     without source-code like builtins and extensions.
+    If `remove_self` is `True`, the first parameter whose name is self
+    will be removed.
     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, ignore_unknown)
+    result = PyDocExtractor().get_calltip(pyobject, ignore_unknown)
+    if remove_self:
+        return result.replace('(self)', '()').replace('(self, ', '(')
+    return result
 def get_definition_location(project, source_code, offset,


         doc = get_calltip(self.project, src, 1, ignore_unknown=True)
         self.assertTrue(doc is None)
+    def test_removing_self_parameter(self):
+        src = 'class C(object):\n' \
+              '    def f(self):\n'\
+              '        pass\n' \
+              'C().f()'
+        doc = get_calltip(self.project, src, src.rindex('f'), remove_self=True)
+        self.assertEquals('C.f()', doc)
+    def test_removing_self_parameter_and_more_than_one_parameter(self):
+        src = 'class C(object):\n' \
+              '    def f(self, p1):\n'\
+              '        pass\n' \
+              'C().f()'
+        doc = get_calltip(self.project, src, src.rindex('f'), remove_self=True)
+        self.assertEquals('C.f(p1)', doc)
 class CodeAssistInProjectsTest(unittest.TestCase):
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.