Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
23 changes: 23 additions & 0 deletions 23 Lib/test/test_unpack_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,29 @@
...
TypeError: 'list' object is not a mapping

>>> class MappingWithKeyErrors:
... def __init__(self, *, keys_error=None, getitem_error=None):
... self.keys_error = keys_error
... self.getitem_error = getitem_error
... def keys(self):
... if self.keys_error is not None:
... raise self.keys_error("error in keys")
... return [1, 2, 3]
... def __getitem__(self, key):
... if self.getitem_error is not None:
... raise self.getitem_error("error in __getitem__")
... return key * 2

>>> {**MappingWithKeyErrors(keys_error=AttributeError)}
Traceback (most recent call last):
...
AttributeError: error in keys

>>> {**MappingWithKeyErrors(getitem_error=AttributeError)}
Traceback (most recent call last):
...
AttributeError: error in __getitem__

>>> len(eval("{" + ", ".join("**{{{}: {}}}".format(i, i)
... for i in range(1000)) + "}"))
1000
Expand Down
21 changes: 18 additions & 3 deletions 21 Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2244,9 +2244,24 @@ 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();
PyObject *keys = NULL;
int has_keys = PyObject_GetOptionalAttr(update_o, &_Py_ID(keys), &keys);

if (has_keys < 0) {
Comment on lines +2247 to +2251

Copilot AI Mar 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DICT_UPDATE now preserves the original AttributeError only when update_o has a keys attribute, but the tier-2 interpreter (Python/executor_cases.c.h) is generated from bytecodes.c and currently still contains the old unconditional conversion of AttributeError into TypeError. This will make behavior differ between tier-1 and tier-2 execution (and can break the new tests when tier-2 is enabled). Please regenerate/update the tier-2 cases so DICT_UPDATE matches this new logic everywhere.

Copilot uses AI. Check for mistakes.
Py_XDECREF(keys);
Py_DECREF(exc);
}
else if (has_keys == 0) {
Py_DECREF(exc);
_PyErr_Format(tstate, PyExc_TypeError,
"'%.200s' object is not a mapping",
Py_TYPE(update_o)->tp_name);
}
else {
Py_DECREF(keys);
PyErr_SetRaisedException(exc);
}
}
PyStackRef_CLOSE(update);
ERROR_IF(true);
Expand Down
28 changes: 25 additions & 3 deletions 28 Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.