Author: Alex Gaynor <alex.gay...@gmail.com> Branch: release-pypy3.5-5.x Changeset: r90922:afcbd079e7f4 Date: 2017-04-02 20:36 +0300 http://bitbucket.org/pypy/pypy/changeset/afcbd079e7f4/
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 @@ -1007,6 +1007,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 @@ -227,6 +227,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_items(self): d = {1: 2, 3: 4} its = list(d.items()) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit