gh-145876: Do not mask KeyErrors raised during dictionary unpacking in call (GH-146472)

KeyErrors raised in keys() or __getitem__() during dictionary unpacking
in call (func(**mymapping)) are no longer masked by TypeError.
This commit is contained in:
Serhiy Storchaka 2026-03-29 11:58:52 +03:00 committed by GitHub
parent 1af025dd22
commit 6932c3ee6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 71 additions and 73 deletions

View file

@ -9458,15 +9458,17 @@
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
PyObject *dict_o = PyStackRef_AsPyObjectBorrow(dict);
PyObject *update_o = PyStackRef_AsPyObjectBorrow(update);
PyObject *dupkey = NULL;
stack_pointer[0] = update;
stack_pointer += 1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
_PyFrame_SetStackPointer(frame, stack_pointer);
int err = _PyDict_MergeEx(dict_o, update_o, 2);
int err = _PyDict_MergeUniq(dict_o, update_o, &dupkey);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (err < 0) {
_PyFrame_SetStackPointer(frame, stack_pointer);
_PyEval_FormatKwargsError(tstate, callable_o, update_o);
_PyEval_FormatKwargsError(tstate, callable_o, update_o, dupkey);
Py_XDECREF(dupkey);
stack_pointer = _PyFrame_GetStackPointer(frame);
SET_CURRENT_CACHED_VALUES(0);
JUMP_TO_ERROR();