Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e670bd4

Browse files
committed
fix #1409: cell variables were not initialized,
when the value comes from a keyword-only parameter.
1 parent 2af1d89 commit e670bd4

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lib/test/test_scope.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@ def str(self):
166166
self.assertEqual(t.method_and_var(), "method")
167167
self.assertEqual(t.actual_global(), "global")
168168

169+
def testCellIsKwonlyArg(self):
170+
# Issue 1409: Initialisation of a cell value,
171+
# when it comes from a keyword-only parameter
172+
def foo(*, a=17):
173+
def bar():
174+
return a + 5
175+
return bar() + 3
176+
177+
self.assertEqual(foo(a=42), 50)
178+
self.assertEqual(foo(), 25)
179+
169180
def testRecursion(self):
170181

171182
def f(x):

Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2708,7 +2708,7 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
27082708
Py_UNICODE *cellname, *argname;
27092709
PyObject *c;
27102710

2711-
nargs = co->co_argcount;
2711+
nargs = co->co_argcount + co->co_kwonlyargcount;
27122712
if (co->co_flags & CO_VARARGS)
27132713
nargs++;
27142714
if (co->co_flags & CO_VARKEYWORDS)

0 commit comments

Comments
 (0)