mirror of
https://github.com/python/cpython.git
synced 2026-04-16 00:31:03 +00:00
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:
parent
e1d4823797
commit
0e543055b0
8 changed files with 418 additions and 16 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue