Repository: serge-sans-paille/beniget

Issue:
Regression in Lambda functions
This new test was passing in version 0.4.1 and now shows nothing

```python
    def test_simple_lambda(self):
        code = "lambda y: True"
        node = ast.parse(code)
        c = beniget.DefUseChains()
        c.visit(node)
        self.assertEqual(c.dump_chains(node), [])
        self.assertEqual(c.dump_chains(node.body[0].value), ['y -> ()'])
```

Discussion:

Patch:
diff --git a/beniget/beniget.py b/beniget/beniget.py
index 50f035b..c964c50 100644
--- a/beniget/beniget.py
+++ b/beniget/beniget.py
@@ -1025,11 +1025,19 @@ class DefUseChains(ast.NodeVisitor):
     def visit_Lambda(self, node, step=DeclarationStep):
         if step is DeclarationStep:
             dnode = self.chains.setdefault(node, Def(node))
+            for default in node.args.defaults:
+                self.visit(default).add_user(dnode)
+            self._defered.append((node,
+                                  list(self._definitions),
+                                  list(self._scopes),
+                                  list(self._scope_depths),
+                                  list(self._precomputed_locals)))
             return dnode
         elif step is DefinitionStep:
             dnode = self.chains[node]
             with self.ScopeContext(node):
-                self.visit(node.args)
+                for a in node.args.args:
+                    self.visit(a)
                 self.visit(node.body).add_user(dnode)
             return dnode
         else:


Test patch:
diff --git a/tests/test_chains.py b/tests/test_chains.py
index e9d33f8..288ccc6 100644
--- a/tests/test_chains.py
+++ b/tests/test_chains.py
@@ -332,6 +332,22 @@ while done:
     def test_simple_import_as(self):
         code = "import x as y; y()"
         self.checkChains(code, ["y -> (y -> (Call -> ()))"])
+    
+    def test_simple_lambda(self):
+        node, c = self.checkChains( "lambda y: True", [])
+        self.assertEqual(c.dump_chains(node.body[0].value), ['y -> ()'])
+    
+    def test_lambda_defaults(self):
+        node, c = self.checkChains( "x=y=1;(lambda y, x=x: (True, x, y, z)); x=y=z=2", 
+                                   ['x -> (x -> (Lambda -> ()))',
+                                    'y -> ()', 
+                                    'x -> ()', 
+                                    'y -> ()',
+                                    'z -> (z -> (Tuple -> (Lambda -> ())))']) 
+        self.assertEqual(c.dump_chains(node.body[1].value), [
+            'y -> (y -> (Tuple -> (Lambda -> ())))',
+            'x -> (x -> (Tuple -> (Lambda -> ())))',
+        ])
 
     def test_multiple_import_as(self):
         code = "import x as y, z; y"