[pypy-svn] r78818 - in pypy/branch/fast-forward/pypy/objspace/std: . test

arigo at codespeak.net arigo at codespeak.net
Sun Nov 7 16:13:46 CET 2010


Author: arigo
Date: Sun Nov  7 16:13:45 2010
New Revision: 78818

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.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:13:45 2010
@@ -197,19 +197,19 @@
 
 #end helper functions
 
-def set_update__Set_BaseSet(space, w_left, w_other):
-    # optimization only (the general case works too)
-    ld, rd = w_left.setdata, w_other.setdata
-    ld.update(rd)
-
-def set_update__Set_ANY(space, w_left, w_other):
+def set_update__Set(space, w_left, others_w):
     """Update a set with the union of itself and another."""
     ld = w_left.setdata
-    for w_item in space.listview(w_other):
-        ld[w_item] = None
+    for w_other in others_w:
+        if isinstance(w_other, W_BaseSetObject):
+            ld.update(w_other.setdata)     # optimization only
+        else:
+            for w_key in space.listview(w_other):
+                ld[w_key] = None
 
 def inplace_or__Set_Set(space, w_left, w_other):
-    set_update__Set_BaseSet(space, w_left, w_other)
+    ld, rd = w_left.setdata, w_other.setdata
+    ld.update(rd)
     return w_left
 
 inplace_or__Set_Frozenset = inplace_or__Set_Set
@@ -597,8 +597,7 @@
 or__Frozenset_Frozenset = or__Set_Set
 
 def set_union__Set(space, w_left, others_w):
-    ld = w_left.setdata
-    result = ld.copy()
+    result = w_left.setdata.copy()
     for w_other in others_w:
         if isinstance(w_other, W_BaseSetObject):
             result.update(w_other.setdata)     # optimization only

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:13:45 2010
@@ -52,9 +52,9 @@
 set_union                       = SMM('union', 1, varargs_w=True,
                                       doc='Return a new set with elements'
                                           ' from the set and all others.')
-set_update                      = SMM('update', 2,
-                                      doc='Update a set with the union of'
-                                          ' itself and another.')
+set_update                      = SMM('update', 1, varargs_w=True,
+                                      doc='Update the set, adding elements'
+                                          ' from all others.')
 set_reduce                      = SMM('__reduce__',1,
                                       doc='Return state information for'
                                           ' pickling.')

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:13:45 2010
@@ -144,6 +144,15 @@
         s1 = set('abc')
         s1.update(frozenset('fro'))
         assert s1 == set('abcfro')
+        s1 = set('abc')
+        s1.update('def')
+        assert s1 == set('abcdef')
+        s1 = set('abc')
+        s1.update()
+        assert s1 == set('abc')
+        s1 = set('abc')
+        s1.update('d', 'ef', frozenset('g'))
+        assert s1 == set('abcdefg')
 
     def test_recursive_repr(self):
         class A(object):



More information about the Pypy-commit mailing list