[pypy-commit] pypy set-strategies: test and fix for W_SetObject.pop()
l.diekmann
noreply at buildbot.pypy.org
Thu Nov 10 13:49:23 CET 2011
Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: set-strategies
Changeset: r49142:8ade98db780b
Date: 2011-05-01 17:35 +0200
http://bitbucket.org/pypy/pypy/changeset/8ade98db780b/
Log: test and fix for W_SetObject.pop()
diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -208,7 +208,7 @@
w_set.add(w_key)
def delitem(self, w_set, w_item):
- # only used internally
+ # not a normal set operation; only used internally
d = self.cast_from_void_star(w_set.sstorage)
try:
del d[self.unwrap(w_item)]
@@ -729,12 +729,14 @@
return space.wrap(hash)
def set_pop__Set(space, w_left):
- for w_key in w_left.setdata:
+ #XXX move this to strategy so we don't have to
+ # wrap all items only to get the first one
+ for w_key in w_left.getkeys():
break
else:
raise OperationError(space.w_KeyError,
space.wrap('pop from an empty set'))
- del w_left.setdata[w_key]
+ w_left.delitem(w_key)
return w_key
def and__Set_Set(space, w_left, w_other):
diff --git a/pypy/objspace/std/test/test_setobject.py b/pypy/objspace/std/test/test_setobject.py
--- a/pypy/objspace/std/test/test_setobject.py
+++ b/pypy/objspace/std/test/test_setobject.py
@@ -88,6 +88,13 @@
raises(KeyError, "a.remove(6)")
+ def test_pop(self):
+ a = set([1,2,3,4,5])
+ for i in xrange(5):
+ a.pop()
+ assert a == set()
+ raises(KeyError, "a.pop()")
+
def test_subtype(self):
class subset(set):pass
a = subset()
More information about the pypy-commit
mailing list