Author: Alex Gaynor <alex.gay...@gmail.com> Branch: release-pypy2.7-5.x Changeset: r90824:1aab6418ec7d Date: 2017-03-27 19:17 +0300 http://bitbucket.org/pypy/pypy/changeset/1aab6418ec7d/
Log: 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) diff --git a/pypy/objspace/std/dictmultiobject.py b/pypy/objspace/std/dictmultiobject.py --- a/pypy/objspace/std/dictmultiobject.py +++ b/pypy/objspace/std/dictmultiobject.py @@ -1049,6 +1049,8 @@ 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 --- a/pypy/objspace/std/test/test_dictmultiobject.py +++ b/pypy/objspace/std/test/test_dictmultiobject.py @@ -161,7 +161,7 @@ w_d.initialize_content([(w(1), wb("a")), (w(2), wb("b"))]) w_l = self.space.call_method(w_d, "keys") assert sorted(self.space.listview_int(w_l)) == [1,2] - + # make sure that .keys() calls newlist_bytes for string dicts def not_allowed(*args): assert False, 'should not be called' @@ -174,7 +174,7 @@ # XXX: it would be nice if the test passed without monkeypatch.undo(), # but we need space.newlist_unicode for it - monkeypatch.undo() + monkeypatch.undo() w_d = self.space.newdict() w_d.initialize_content([(w(u"a"), w(1)), (w(u"b"), w(6))]) w_l = self.space.call_method(w_d, "keys") @@ -223,6 +223,10 @@ 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_has_key(self): d = {1: 2, 3: 4} assert d.has_key(1) @@ -1466,4 +1470,3 @@ fakespace = FakeSpace() d = fakespace.newdict(module=True) assert type(d.get_strategy()) is BytesDictStrategy - _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit