[pypy-commit] pypy set-strategies: added test and fix for issubset and issuperset

l.diekmann noreply at buildbot.pypy.org
Thu Nov 10 13:49:26 CET 2011


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: set-strategies
Changeset: r49144:b22d4b425150
Date: 2011-05-02 13:27 +0200
http://bitbucket.org/pypy/pypy/changeset/b22d4b425150/

Log:	added test and fix for issubset and issuperset

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
@@ -322,6 +322,10 @@
         w_set.sstorage = result.sstorage
 
     def issubset(self, w_set, w_other):
+        if not isinstance(w_other, W_BaseSetObject):
+            setdata = make_setdata_from_w_iterable(self.space, w_other)
+            w_other = w_set._newobj(self.space, setdata)
+
         if w_set.length() > w_other.length():
             return False
 
@@ -572,7 +576,7 @@
 eq__Frozenset_Set = eq__Set_Set
 
 def eq__Set_settypedef(space, w_left, w_other):
-    #XXX what is faster: wrapping w_left or creating set from w_other
+    #XXX dont know how to test this
     rd = make_setdata_from_w_iterable(space, w_other)
     return space.wrap(_is_eq(w_left.setdata, rd))
 
@@ -635,8 +639,7 @@
     if space.is_w(w_left, w_other):
         return space.w_True
 
-    ld, rd = w_left.setdata, make_setdata_from_w_iterable(space, w_other)
-    return space.wrap(_issubset_dict(ld, rd))
+    return space.wrap(w_left.issubset(w_other))
 
 frozenset_issubset__Frozenset_ANY = set_issubset__Set_ANY
 
@@ -661,8 +664,11 @@
     if space.is_w(w_left, w_other):
         return space.w_True
 
-    ld, rd = w_left.setdata, make_setdata_from_w_iterable(space, w_other)
-    return space.wrap(_issubset_dict(rd, ld))
+    #XXX BAD
+    setdata = make_setdata_from_w_iterable(space, w_other)
+    w_other = w_left._newobj(space, setdata)
+
+    return space.wrap(w_other.issubset(w_left))
 
 frozenset_issuperset__Frozenset_ANY = set_issuperset__Set_ANY
 
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
@@ -85,6 +85,20 @@
         a -= b
         assert a == set([2,3])
 
+    def test_issubset(self):
+        a = set([1,2,3,4])
+        b = set([2,3])
+        assert b.issubset(a)
+        c = [1,2,3,4]
+        assert b.issubset(c)
+
+    def test_issuperset(self):
+        a = set([1,2,3,4])
+        b = set([2,3])
+        assert a.issuperset(b)
+        c = [2,3]
+        assert a.issuperset(c)
+
     def test_discard_remove(self):
         a = set([1,2,3,4,5])
         a.remove(1)


More information about the pypy-commit mailing list