darren.hoo avatar darren.hoo committed b0d3b4e

add methods for Lambda needed by get_calltip

Comments (0)

Files changed (2)

rope/base/builtins.py

 import inspect
 
 import rope.base.evaluate
-from rope.base import pynames, pyobjects, arguments, utils
+from rope.base import pynames, pyobjects, arguments, utils, ast
 
 
 class BuiltinModule(pyobjects.AbstractModule):
     def __init__(self, node, scope):
         super(Lambda, self).__init__()
         self.node = node
+        self.arguments = node.args
         self.scope = scope
 
     def get_returned_object(self, args):
     def get_pattributes(self):
         return {}
 
+    def get_name(self):
+        return  'lambda'
+
+    def get_param_names(self):
+        result = [node.id for node in self.arguments.args
+                  if isinstance(node, ast.Name)]
+        if self.arguments.vararg:
+            result.append('*' + self.arguments.vararg)
+        if self.arguments.kwarg:
+            result.append('**' + self.arguments.kwarg)
+        return result
+
+    @property
+    def parent(self):
+        return self.scope.pyobject
+
 
 class BuiltinObject(BuiltinClass):
 

ropetest/builtinstest.py

         self.assertEquals(pyobjects.get_base_type('Function'),
                           l_var.get_type())
 
+    def test_lambda_function_definition(self):
+        self.mod.write('l = lambda x, y = 2, *a, **b: x + y\n')
+        pymod = self.pycore.resource_to_pyobject(self.mod)
+        l_var = pymod['l'].get_object()
+        self.assertTrue(l_var.get_name() is not None)
+        self.assertEquals(len(l_var.get_param_names()), 4)
+        self.assertEquals((pymod, 1),
+                          pymod['l'].get_definition_location())
+
     def test_lambdas_that_return_unknown(self):
         self.mod.write('a_var = (lambda: None)()\n')
         pymod = self.pycore.resource_to_pyobject(self.mod)
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.