summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2007-11-24 00:29:24 +0000
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2007-11-24 00:29:24 +0000
commit12dcfac6bbe8b94ae7d7f1cf6b67346049b81e9a (patch)
tree5d62b2942b2e3cb90bdc0d0e875990e1ccb5ddf8
parent6a9bae65553c52fb0a5e2a04371413baf88985ab (diff)
downloadcpython-12dcfac6bbe8b94ae7d7f1cf6b67346049b81e9a.tar.gz
fix #1409: cell variables were not initialized,
when the value comes from a keyword-only parameter.
-rw-r--r--Lib/test/test_scope.py11
-rw-r--r--Python/ceval.c2
2 files changed, 12 insertions, 1 deletions
diff --git a/Lib/test/test_scope.py b/Lib/test/test_scope.py
index 22f254a321..ccb9016808 100644
--- a/Lib/test/test_scope.py
+++ b/Lib/test/test_scope.py
@@ -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):
diff --git a/Python/ceval.c b/Python/ceval.c
index 70086e1c21..b4efa33e74 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -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)