[pypy-svn] r78819 - in pypy/branch/fast-forward/pypy/objspace/std: . test
arigo at codespeak.net
arigo at codespeak.net
Sun Nov 7 16:19:23 CET 2010
Author: arigo
Date: Sun Nov 7 16:19:22 2010
New Revision: 78819
Modified:
pypy/branch/fast-forward/pypy/objspace/std/setobject.py
pypy/branch/fast-forward/pypy/objspace/std/settype.py
pypy/branch/fast-forward/pypy/objspace/std/test/test_setobject.py
Log:
set.intersection_update(more_than_one_argument).
Modified: pypy/branch/fast-forward/pypy/objspace/std/setobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/setobject.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/setobject.py Sun Nov 7 16:19:22 2010
@@ -482,10 +482,8 @@
and__Frozenset_Set = and__Set_Set
and__Frozenset_Frozenset = and__Set_Set
-def set_intersection__Set(space, w_left, others_w):
+def _intersection_multiple(space, w_left, others_w):
result = w_left.setdata
- if len(others_w) == 0:
- result = result.copy()
for w_other in others_w:
if isinstance(w_other, W_BaseSetObject):
# optimization only
@@ -496,28 +494,25 @@
if w_key in result:
result2[w_key] = None
result = result2
+ return result
+
+def set_intersection__Set(space, w_left, others_w):
+ if len(others_w) == 0:
+ result = w_left.setdata.copy()
+ else:
+ result = _intersection_multiple(space, w_left, others_w)
return w_left._newobj(space, result)
frozenset_intersection__Frozenset = set_intersection__Set
-def set_intersection_update__Set_Set(space, w_left, w_other):
- # optimization only (the general case works too)
- ld, rd = w_left.setdata, w_other.setdata
- new_ld = _intersection_dict(space, ld, rd)
- w_left.setdata = new_ld
-
-set_intersection_update__Set_Frozenset = set_intersection_update__Set_Set
-
-def set_intersection_update__Set_ANY(space, w_left, w_other):
- result = newset(space)
- ld = w_left.setdata
- for w_key in space.listview(w_other):
- if w_key in ld:
- result[w_key] = None
+def set_intersection_update__Set(space, w_left, others_w):
+ result = _intersection_multiple(space, w_left, others_w)
w_left.setdata = result
def inplace_and__Set_Set(space, w_left, w_other):
- set_intersection_update__Set_Set(space, w_left, w_other)
+ ld, rd = w_left.setdata, w_other.setdata
+ new_ld = _intersection_dict(space, ld, rd)
+ w_left.setdata = new_ld
return w_left
inplace_and__Set_Frozenset = inplace_and__Set_Set
Modified: pypy/branch/fast-forward/pypy/objspace/std/settype.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/settype.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/settype.py Sun Nov 7 16:19:22 2010
@@ -24,9 +24,9 @@
set_intersection = SMM('intersection', 1, varargs_w=True,
doc='Return a new set with elements common'
' to the set and all others.')
-set_intersection_update = SMM('intersection_update', 2,
- doc='Update a set with the intersection'
- ' of itself and another.')
+set_intersection_update = SMM('intersection_update', 1, varargs_w=True,
+ doc='Update the set, keeping only elements'
+ ' found in it and all others.')
set_issubset = SMM('issubset', 2,
doc='Report whether another set contains'
' this set.')
Modified: pypy/branch/fast-forward/pypy/objspace/std/test/test_setobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/test/test_setobject.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/test/test_setobject.py Sun Nov 7 16:19:22 2010
@@ -324,3 +324,12 @@
s = set([1,2,3])
assert s.difference() == s
assert s.difference() is not s
+
+ def test_intersection_update(self):
+ s = set([1,2,3,4,7])
+ s.intersection_update([0,1,2,3,4,5,6])
+ assert s == set([1,2,3,4])
+ s.intersection_update((2,3,4,5), frozenset([0,1,2,3]))
+ assert s == set([2,3])
+ s.intersection_update()
+ assert s == set([2,3])
More information about the Pypy-commit
mailing list