gh-145876: Do not mask AttributeErrors raised during dictionary unpacking (GH-145906)

AttributeErrors raised in keys() or __getitem__() during
dictionary unpacking ({**mymapping} or func(**mymapping)) are
no longer masked by TypeError.
This commit is contained in:
Serhiy Storchaka 2026-03-26 15:48:57 +02:00 committed by GitHub
parent e1d4823797
commit 0e543055b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 418 additions and 16 deletions

View file

@ -2390,9 +2390,17 @@ dummy_func(
if (err < 0) {
int matches = _PyErr_ExceptionMatches(tstate, PyExc_AttributeError);
if (matches) {
_PyErr_Format(tstate, PyExc_TypeError,
"'%.200s' object is not a mapping",
Py_TYPE(update_o)->tp_name);
PyObject *exc = _PyErr_GetRaisedException(tstate);
int has_keys = PyObject_HasAttrWithError(update_o, &_Py_ID(keys));
if (has_keys == 0) {
_PyErr_Format(tstate, PyExc_TypeError,
"'%T' object is not a mapping",
update_o);
Py_DECREF(exc);
}
else {
_PyErr_ChainExceptions1(exc);
}
}
ERROR_NO_POP();
}