[pypy-commit] pypy set-strategies: added tests and fix for unhashable items in combination with EmptySetStrategy
l.diekmann
noreply at buildbot.pypy.org
Thu Nov 10 13:51:02 CET 2011
Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: set-strategies
Changeset: r49193:b07c4ba0f7ba
Date: 2011-07-22 16:15 +0200
http://bitbucket.org/pypy/pypy/changeset/b07c4ba0f7ba/
Log: added tests and fix for unhashable items in combination with
EmptySetStrategy
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
@@ -178,6 +178,17 @@
cast_to_void_star = staticmethod(cast_to_void_star)
cast_from_void_star = staticmethod(cast_from_void_star)
+ def check_for_unhashable_objects(self, w_iterable):
+ w_iterator = self.space.iter(w_iterable)
+ while True:
+ try:
+ elem = self.space.next(w_iterator)
+ self.space.hash(elem)
+ except OperationError, e:
+ if not e.match(self.space, self.space.w_StopIteration):
+ raise
+ break
+
def get_empty_storage(self):
return self.cast_to_void_star(None)
@@ -230,22 +241,27 @@
return False
def difference(self, w_set, w_other):
+ self.check_for_unhashable_objects(w_other)
return w_set.copy()
def difference_update(self, w_set, w_other):
- pass
+ self.check_for_unhashable_objects(w_other)
def intersect(self, w_set, w_other):
+ self.check_for_unhashable_objects(w_other)
return w_set.copy()
def intersect_update(self, w_set, w_other):
+ self.check_for_unhashable_objects(w_other)
return w_set.copy()
- def intersect_multiple(self, w_set, w_other):
+ def intersect_multiple(self, w_set, others_w):
+ self.intersect_multiple_update(w_set, others_w)
return w_set.copy()
- def intersect_multiple_update(self, w_set, w_other):
- pass
+ def intersect_multiple_update(self, w_set, others_w):
+ for w_other in others_w:
+ self.intersect(w_set, w_other)
def isdisjoint(self, w_set, w_other):
return True
@@ -828,6 +844,7 @@
w_left.difference_update(w_other)
else:
for w_key in space.listview(w_other):
+ space.hash(w_key)
w_left.delitem(w_key)
def inplace_sub__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
@@ -599,6 +599,15 @@
assert e.isdisjoint(x) == True
assert x.isdisjoint(e) == True
+ def test_empty_typeerror(self):
+ s = set()
+ raises(TypeError, s.difference, [[]])
+ raises(TypeError, s.difference_update, [[]])
+ raises(TypeError, s.intersection, [[]])
+ raises(TypeError, s.intersection_update, [[]])
+ raises(TypeError, s.symmetric_difference, [[]])
+ raises(TypeError, s.symmetric_difference_update, [[]])
+ raises(TypeError, s.update, [[]])
def test_super_with_generator(self):
def foo():
More information about the pypy-commit
mailing list