changeset 203:48fab34e5e4d trunk

Fix for handling function calls with star/dstar arguments in expressions. Closes #42. Many thanks to David Fraser for reporting the problem and providing a patch!
author cmlenz
date Fri, 25 Aug 2006 13:12:39 +0000
parents 92353f28ae54
children 51d4101f49ca
files markup/eval.py markup/tests/eval.py
diffstat 2 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/markup/eval.py
+++ b/markup/eval.py
@@ -243,11 +243,9 @@
         node.node = self.visit(node.node, *args, **kwargs)
         node.args = map(lambda x: self.visit(x, *args, **kwargs), node.args)
         if node.star_args:
-            node.star_args = map(lambda x: self.visit(x, *args, **kwargs),
-                                 node.star_args)
+            node.star_args = self.visit(node.star_args, *args, **kwargs)
         if node.dstar_args:
-            node.dstart_args = map(lambda x: self.visit(x, *args, **kwargs),
-                                   node.dstar_args)
+            node.dstar_args = self.visit(node.dstar_args, *args, **kwargs)
         return node
 
     def visitLambda(self, node, *args, **kwargs):
--- a/markup/tests/eval.py
+++ b/markup/tests/eval.py
@@ -200,6 +200,16 @@
         self.assertEqual(42, Expression("foo(x=bar)").evaluate({'foo': lambda x: x,
                                                                 'bar': 42}))
 
+    def test_call_star_args(self):
+        self.assertEqual(42, Expression("foo(*bar)").evaluate({'foo': lambda x: x,
+                                                               'bar': [42]}))
+
+    def test_call_dstar_args(self):
+        def foo(x):
+            return x
+        self.assertEqual(42, Expression("foo(**bar)").evaluate({'foo': foo,
+                                                                'bar': {"x": 42}}))
+
     def test_call_function_without_params(self):
         self.assertEqual(42, Expression("foo").evaluate({'foo': lambda: 42}))
         data = {'foo': 'bar'}
Copyright (C) 2012-2017 Edgewall Software