Commits

Lukas Diekmann committed 776e724

issue 1183: difference should never reuse the storage of a set as the storage of the resulting set, even if they are equal

  • Participants
  • Parent commits f4ed41f

Comments (0)

Files changed (2)

pypy/objspace/std/setobject.py

             storage = self._difference_unwrapped(w_set, w_other)
         elif not w_set.strategy.may_contain_equal_elements(w_other.strategy):
             strategy = w_set.strategy
-            storage = w_set.sstorage
+            d = self.unerase(w_set.sstorage)
+            storage = self.erase(d.copy())
         else:
             strategy = self.space.fromcache(ObjectSetStrategy)
             storage = self._difference_wrapped(w_set, w_other)

pypy/objspace/std/test/test_setobject.py

         assert set([1,2,3,'5']).difference(set([2,3,4])) == set([1,'5'])
         assert set().difference(set([1,2,3])) == set()
 
+    def test_difference_bug(self):
+        a = set([1,2,3])
+        b = set([])
+        c = a - b
+        c.remove(2)
+        assert c == set([1, 3])
+        assert a == set([1,2, 3])
+
     def test_intersection_update(self):
         s = set([1,2,3,4,7])
         s.intersection_update([0,1,2,3,4,5,6])