Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r75374:0e383b1145e4
Date: 2015-01-16 11:41 +0100
http://bitbucket.org/pypy/pypy/changeset/0e383b1145e4/

Log:    Test and fix: Cls.__dict__.popitem() => segfault instead of KeyError

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
@@ -471,6 +471,8 @@
         # provide a better one.
         iterator = self.iteritems(w_dict)
         w_key, w_value = iterator.next_item()
+        if w_key is None:
+            raise KeyError
         self.delitem(w_dict, w_key)
         return (w_key, w_value)
 
diff --git a/pypy/objspace/std/test/test_dictproxy.py 
b/pypy/objspace/std/test/test_dictproxy.py
--- a/pypy/objspace/std/test/test_dictproxy.py
+++ b/pypy/objspace/std/test/test_dictproxy.py
@@ -16,14 +16,25 @@
         raises(TypeError, 'NotEmpty.__dict__[15] = "y"')
         raises(KeyError, 'del NotEmpty.__dict__[15]')
 
-        key, value = NotEmpty.__dict__.popitem()
-        assert (key == 'a' and value == 1) or (key == 'b' and value == 4)
-
         assert NotEmpty.__dict__.setdefault("string", 1) == 1
         assert NotEmpty.__dict__.setdefault("string", 2) == 1
         assert NotEmpty.string == 1
         raises(TypeError, 'NotEmpty.__dict__.setdefault(15, 1)')
 
+    def test_dictproxy_popitem(self):
+        class A(object):
+            a = 42
+        seen = 0
+        try:
+            while True:
+                key, value = A.__dict__.popitem()
+                if key == 'a':
+                    assert value == 42
+                    seen += 1
+        except KeyError:
+            pass
+        assert seen == 1
+
     def test_dictproxy_getitem(self):
         class NotEmpty(object):
             a = 1
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to