mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
[3.13] gh-132617: Fix dict.update()
mutation check (gh-134815) (gh-135582)
Use `ma_used` instead of `ma_keys->dk_nentries` for modification check
so that we only check if the dictionary is modified, not if new keys are
added to a different dictionary that shared the same keys object.
(cherry picked from commit d8994b0a77
)
This commit is contained in:
parent
404e8aa9f3
commit
f33a5e891a
3 changed files with 38 additions and 2 deletions
|
@ -3782,7 +3782,7 @@ dict_dict_merge(PyInterpreterState *interp, PyDictObject *mp, PyDictObject *othe
|
|||
}
|
||||
}
|
||||
|
||||
Py_ssize_t orig_size = other->ma_keys->dk_nentries;
|
||||
Py_ssize_t orig_size = other->ma_used;
|
||||
Py_ssize_t pos = 0;
|
||||
Py_hash_t hash;
|
||||
PyObject *key, *value;
|
||||
|
@ -3816,7 +3816,7 @@ dict_dict_merge(PyInterpreterState *interp, PyDictObject *mp, PyDictObject *othe
|
|||
if (err != 0)
|
||||
return -1;
|
||||
|
||||
if (orig_size != other->ma_keys->dk_nentries) {
|
||||
if (orig_size != other->ma_used) {
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"dict mutated during update");
|
||||
return -1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue