fix #1409: cell variables were not initialized,

when the value comes from a keyword-only parameter.
This commit is contained in:
Amaury Forgeot d'Arc 2007-11-24 00:29:24 +00:00
parent 2af1d894e3
commit e670bd4f63
2 changed files with 12 additions and 1 deletions

View 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):

View 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)