Author: Lukas Diekmann <[email protected]>
Branch: set-strategies
Changeset: r49172:5cba5090dcca
Date: 2011-05-20 16:02 +0200
http://bitbucket.org/pypy/pypy/changeset/5cba5090dcca/

Log:    fixed bug in difference method for objectsets and added tests

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
@@ -392,7 +392,8 @@
         if not isinstance(w_other, W_BaseSetObject):
             w_other = w_set._newobj(self.space, w_other)
 
-        if w_other.strategy is self.space.fromcache(ObjectSetStrategy):
+        if (w_other.strategy is self.space.fromcache(ObjectSetStrategy) or
+            w_set.strategy is self.space.fromcache(ObjectSetStrategy)):
             return self.difference_wrapped(w_set, w_other)
 
         if w_set.strategy is not w_other.strategy:
@@ -406,12 +407,12 @@
         while True:
             try:
                 w_item = self.space.next(w_iter)
-                if not w_other.has_key(w_key):
-                    result.add(w_key)
+                if not w_other.has_key(w_item):
+                    result.add(w_item)
             except OperationError, e:
                 if not e.match(self.space, self.space.w_StopIteration):
                     raise
-                return
+                break;
         return result
 
     def difference_unwrapped(self, w_set, 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
@@ -451,6 +451,8 @@
         s = set([1,2,3])
         assert s.difference() == s
         assert s.difference() is not s
+        assert set([1,2,3]).difference(set([2,3,4,'5'])) == set([1])
+        assert set([1,2,3,'5']).difference(set([2,3,4])) == set([1,'5'])
 
     def test_intersection_update(self):
         s = set([1,2,3,4,7])
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to