aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2017-04-02 20:36:35 +0300
committerAlex Gaynor <alex.gaynor@gmail.com>2017-04-02 20:36:35 +0300
commit9f6bd5d53b3feda3251e89764eba7242aeee711b (patch)
treeec828b1d70d3d4c2198456c9dd96e0309f04d522
parentmerge py3.5 into release-pypy3 (diff)
downloadpypy-9f6bd5d53b3feda3251e89764eba7242aeee711b.tar.gz
pypy-9f6bd5d53b3feda3251e89764eba7242aeee711b.tar.bz2
pypy-9f6bd5d53b3feda3251e89764eba7242aeee711b.zip
Fixes #2508 -- correctly handle dict.pop where the popping key is not the same type as the dict's and pop is called with a default
(grafted from a1b0ce5e4915a6e46c9007f81a991cbaf179f027)
-rw-r--r--pypy/objspace/std/dictmultiobject.py2
-rw-r--r--pypy/objspace/std/test/test_dictmultiobject.py4
2 files changed, 6 insertions, 0 deletions
diff --git a/pypy/objspace/std/dictmultiobject.py b/pypy/objspace/std/dictmultiobject.py
index 1ecf950a83..fffd39178d 100644
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -1007,6 +1007,8 @@ class AbstractTypedStrategy(object):
else:
return d.pop(key, w_default)
elif self._never_equal_to(space.type(w_key)):
+ if w_default is not None:
+ return w_default
raise KeyError
else:
self.switch_to_object_strategy(w_dict)
diff --git a/pypy/objspace/std/test/test_dictmultiobject.py b/pypy/objspace/std/test/test_dictmultiobject.py
index 880d6bdd41..5b700404a4 100644
--- a/pypy/objspace/std/test/test_dictmultiobject.py
+++ b/pypy/objspace/std/test/test_dictmultiobject.py
@@ -227,6 +227,10 @@ class AppTest_DictObject:
assert len(dd) == 1
raises(KeyError, dd.pop, 33)
+ assert d.pop("abc", None) is None
+ raises(KeyError, d.pop, "abc")
+ assert len(d) == 2
+
def test_items(self):
d = {1: 2, 3: 4}
its = list(d.items())