]> granicus.if.org Git - python/commitdiff
fix #1409: cell variables were not initialized,
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Sat, 24 Nov 2007 00:29:24 +0000 (00:29 +0000)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Sat, 24 Nov 2007 00:29:24 +0000 (00:29 +0000)
when the value comes from a keyword-only parameter.

Lib/test/test_scope.py
Python/ceval.c

index 22f254a321e57deac5ee0425d18597edb0c501df..ccb9016808ad821f6fd9061c3229f61a7a655032 100644 (file)
@@ -166,6 +166,17 @@ class ScopeTests(unittest.TestCase):
         self.assertEqual(t.method_and_var(), "method")
         self.assertEqual(t.actual_global(), "global")
 
+    def testCellIsKwonlyArg(self):
+        # Issue 1409: Initialisation of a cell value,
+        # when it comes from a keyword-only parameter
+        def foo(*, a=17):
+            def bar():
+                return a + 5
+            return bar() + 3
+
+        self.assertEqual(foo(a=42), 50)
+        self.assertEqual(foo(), 25)
+
     def testRecursion(self):
 
         def f(x):
index 70086e1c217a507cb1257bbf3f1b9433d0476b1e..b4efa33e7496dcb2c30912e8621e61858f6fe8d9 100644 (file)
@@ -2708,7 +2708,7 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
                Py_UNICODE *cellname, *argname;
                PyObject *c;
 
-               nargs = co->co_argcount;
+               nargs = co->co_argcount + co->co_kwonlyargcount;
                if (co->co_flags & CO_VARARGS)
                        nargs++;
                if (co->co_flags & CO_VARKEYWORDS)