Author: Lukas Diekmann <[email protected]>
Branch: set-strategies
Changeset: r49155:14b4c0d3850a
Date: 2011-05-13 15:42 +0200
http://bitbucket.org/pypy/pypy/changeset/14b4c0d3850a/
Log: fixed bug in issuperset, more tests, some optimization
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
@@ -478,12 +478,15 @@
w_set.sstorage = result.sstorage
def issuperset(self, w_set, w_other):
- #XXX other is empty is always True
- if w_set.length() < self.space.unwrap(self.space.len(w_other)):
- return False
- for w_key in self.space.unpackiterable(w_other):
- if not w_set.has_key(w_key):
- return False
+ #XXX always True if other is empty
+ w_iter = self.space.iter(w_other)
+ while True:
+ try:
+ w_item = self.space.next(w_iter)
+ if not w_set.has_key(w_item):
+ return False
+ except OperationError:
+ return True
return True
def isdisjoint(self, w_set, w_other):
@@ -818,6 +821,8 @@
# optimization only (the general case works too)
if space.is_w(w_left, w_other):
return space.w_True
+ if w_left.length() > w_other.length():
+ return space.w_False
return space.wrap(w_other.issuperset(w_left))
set_issubset__Set_Frozenset = set_issubset__Set_Set
@@ -829,6 +834,9 @@
return space.w_True
w_other_as_set = w_left._newobj(space, w_other)
+
+ if w_left.length() > w_other_as_set.length():
+ return space.w_False
return space.wrap(w_other_as_set.issuperset(w_left))
frozenset_issubset__Frozenset_ANY = set_issubset__Set_ANY
@@ -842,6 +850,8 @@
# optimization only (the general case works too)
if space.is_w(w_left, w_other):
return space.w_True
+ if w_left.length() < w_other.length():
+ return space.w_False
return space.wrap(w_left.issuperset(w_other))
set_issuperset__Set_Frozenset = set_issuperset__Set_Set
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
@@ -115,6 +115,10 @@
c = [2,3]
assert a.issuperset(c)
+ c = [1,1,1,1,1]
+ assert a.issuperset(c)
+ assert set([1,1,1,1,1]).issubset(a)
+
def test_inplace_and(test):
a = set([1,2,3,4])
b = set([0,2,3,5,6])
@@ -518,3 +522,10 @@
assert e.isdisjoint(e) == True
assert e.isdisjoint(x) == True
assert x.isdisjoint(e) == True
+
+
+ def test_super_with_generator(self):
+ def foo():
+ for i in [1,2,3]:
+ yield i
+ set([1,2,3,4,5]).issuperset(foo())
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit