[Python-checkins] cpython (merge 3.6 -> default): Merge 3.6 (fix dict.pop)
victor.stinner
python-checkins at python.org
Tue Sep 13 11:02:47 EDT 2016
https://hg.python.org/cpython/rev/b347e918d08f
changeset: 103764:b347e918d08f
parent: 103762:23270dae3c9e
parent: 103763:dc627ef9020f
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Sep 13 16:57:01 2016 +0200
summary:
Merge 3.6 (fix dict.pop)
files:
Lib/test/test_dict.py | 9 +++++++++
Misc/NEWS | 3 +++
Objects/dictobject.c | 2 +-
3 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -892,6 +892,15 @@
self.assertEqual(list(b), ['x', 'y', 'z'])
@support.cpython_only
+ def test_splittable_pop_pending(self):
+ """pop a pending key in a splitted table should not crash"""
+ a, b = self.make_shared_key_dict(2)
+
+ a['a'] = 4
+ with self.assertRaises(KeyError):
+ b.pop('a')
+
+ @support.cpython_only
def test_splittable_popitem(self):
"""split table must be combined when d.popitem()"""
a, b = self.make_shared_key_dict(2)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
Core and Builtins
-----------------
+- Issue #28120: Fix dict.pop() for splitted dictionary when trying to remove a
+ "pending key" (Not yet inserted in split-table). Patch by Xiang Zhang.
+
Library
-------
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -1721,7 +1721,7 @@
ix = (mp->ma_keys->dk_lookup)(mp, key, hash, &value_addr, &hashpos);
if (ix == DKIX_ERROR)
return NULL;
- if (ix == DKIX_EMPTY) {
+ if (ix == DKIX_EMPTY || *value_addr == NULL) {
if (deflt) {
Py_INCREF(deflt);
return deflt;
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list