Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,7 @@ def getcallargs(*func_and_positional, **named):
possible_kwargs = set(args + kwonlyargs)
if varkw:
arg2value[varkw] = {}
possible_kwargs -= set(args[:n])
for kw, value in named.items():
if kw not in possible_kwargs:
if not varkw:
Expand Down
8 changes: 5 additions & 3 deletions Lib/test/test_extcall.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,13 @@
>>> d
{}


>>> g(1, 2, 3, **{'x': 4, 'y': 5})
>>> h(1, 2, **{'a': 4, 'h': 5})
Traceback (most recent call last):
...
TypeError: g() got multiple values for argument 'x'
TypeError: h() got multiple values for argument 'a'

>>> g(1, 2, 3, **{'x': 4, 'y': 5})
1 (2, 3) {'x': 4, 'y': 5}

>>> f(**{1:2})
Traceback (most recent call last):
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,7 @@ def test_varkw(self):
self.assertEqualCallArgs(f, '**collections.UserDict(a=2, b=3, c=4)')
self.assertEqualCallArgs(f, '2, c=4, **collections.UserDict(b=3)')
self.assertEqualCallArgs(f, 'b=2, **collections.UserDict(a=3, c=4)')
self.assertEqualCallArgs(f, '1, a=2')

def test_varkw_only(self):
# issue11256:
Expand Down
4 changes: 2 additions & 2 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -3858,15 +3858,15 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
/* Speed hack: do raw pointer compares. As names are
normally interned this should almost always hit. */
co_varnames = ((PyTupleObject *)(co->co_varnames))->ob_item;
for (j = 0; j < total_args; j++) {
for (j = (kwdict ? n : 0); j < total_args; j++) {
PyObject *name = co_varnames[j];
if (name == keyword) {
goto kw_found;
}
}

/* Slow fallback, just in case */
for (j = 0; j < total_args; j++) {
for (j = (kwdict ? n : 0); j < total_args; j++) {
PyObject *name = co_varnames[j];
int cmp = PyObject_RichCompareBool( keyword, name, Py_EQ);
if (cmp > 0) {
Expand Down