[pypy-svn] r31319 - in pypy/dist/pypy/objspace/std: . test

arigo at codespeak.net arigo at codespeak.net
Tue Aug 15 14:51:23 CEST 2006


Author: arigo
Date: Tue Aug 15 14:51:18 2006
New Revision: 31319

Modified:
   pypy/dist/pypy/objspace/std/dictmultiobject.py
   pypy/dist/pypy/objspace/std/dictobject.py
   pypy/dist/pypy/objspace/std/dictstrobject.py
   pypy/dist/pypy/objspace/std/dicttype.py
   pypy/dist/pypy/objspace/std/test/test_dictobject.py
Log:
issue244 testing

Added keyword arguments to dict.update().


Modified: pypy/dist/pypy/objspace/std/dictmultiobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictmultiobject.py	(original)
+++ pypy/dist/pypy/objspace/std/dictmultiobject.py	Tue Aug 15 14:51:18 2006
@@ -327,8 +327,8 @@
         else:
             w_self.implementation = EmptyDictImplementation(space)
         if w_otherdict is not None:
-            from pypy.objspace.std.dicttype import dict_update__ANY_ANY
-            dict_update__ANY_ANY(space, w_self, w_otherdict)
+            from pypy.objspace.std.dicttype import update1
+            update1(space, w_self, w_otherdict)
 
     def initialize_content(w_self, list_pairs_w):
         impl = w_self.implementation
@@ -377,11 +377,11 @@
             w_dict.implementation = w_dict.implementation.setitem(w_k, w_v)
     else:
         if space.is_true(w_src):
-            from pypy.objspace.std.dicttype import dict_update__ANY_ANY
-            dict_update__ANY_ANY(space, w_dict, w_src)
+            from pypy.objspace.std.dicttype import update1
+            update1(space, w_dict, w_src)
     if space.is_true(w_kwds):
-        from pypy.objspace.std.dicttype import dict_update__ANY_ANY
-        dict_update__ANY_ANY(space, w_dict, w_kwds)
+        from pypy.objspace.std.dicttype import update1
+        update1(space, w_dict, w_kwds)
 
 def getitem__DictMulti_ANY(space, w_dict, w_lookup):
     try:

Modified: pypy/dist/pypy/objspace/std/dictobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictobject.py	(original)
+++ pypy/dist/pypy/objspace/std/dictobject.py	Tue Aug 15 14:51:18 2006
@@ -65,11 +65,11 @@
             w_dict.content[w_k] = w_v
     else:
         if space.is_true(w_src):
-            from pypy.objspace.std.dicttype import dict_update__ANY_ANY
-            dict_update__ANY_ANY(space, w_dict, w_src)
+            from pypy.objspace.std.dicttype import update1
+            update1(space, w_dict, w_src)
     if space.is_true(w_kwds):
-        from pypy.objspace.std.dicttype import dict_update__ANY_ANY
-        dict_update__ANY_ANY(space, w_dict, w_kwds)
+        from pypy.objspace.std.dicttype import update1
+        update1(space, w_dict, w_kwds)
 
 def getitem__Dict_ANY(space, w_dict, w_lookup):
     try:

Modified: pypy/dist/pypy/objspace/std/dictstrobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictstrobject.py	(original)
+++ pypy/dist/pypy/objspace/std/dictstrobject.py	Tue Aug 15 14:51:18 2006
@@ -121,11 +121,11 @@
             w_dict.setitem(w_k, w_v)
     else:
         if space.is_true(w_src):
-            from pypy.objspace.std.dicttype import dict_update__ANY_ANY
-            dict_update__ANY_ANY(space, w_dict, w_src)
+            from pypy.objspace.std.dicttype import update1
+            update1(space, w_dict, w_src)
     if space.is_true(w_kwds):
-        from pypy.objspace.std.dicttype import dict_update__ANY_ANY
-        dict_update__ANY_ANY(space, w_dict, w_kwds)
+        from pypy.objspace.std.dicttype import update1
+        update1(space, w_dict, w_kwds)
 
 def getitem__DictStr_ANY(space, w_dict, w_lookup):
     try:

Modified: pypy/dist/pypy/objspace/std/dicttype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dicttype.py	(original)
+++ pypy/dist/pypy/objspace/std/dicttype.py	Tue Aug 15 14:51:18 2006
@@ -30,7 +30,7 @@
 dict_setdefault = SMM('setdefault',    3, defaults=(None,),
                       doc='D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d'
                           ' if k not in D')
-dict_update     = SMM('update',        2, defaults=((),),
+dict_update     = SMM('update',        1, general__args__=True,
                       doc='D.update(E, **F) -> None.  Update D from E and F:'
                           ' for k in E: D[k] = E[k]\n(if E has keys else: for'
                           ' (k, v) in E: D[k] = v) then: for k in F: D[k] ='
@@ -55,7 +55,7 @@
 # gateway is imported in the stdtypedef module
 app = gateway.applevel('''
 
-    def update(d, o):
+    def update1(d, o):
         if hasattr(o, 'keys'):
             for k in o.keys():
                 d[k] = o[k]
@@ -63,6 +63,14 @@
             for k,v in o:
                 d[k] = v
 
+    def update(d, *args, **kwargs):
+        if len(args) == 1:
+            update1(d, args[0])
+        elif len(args) > 1:
+            raise TypeError("update takes at most 1 (non-keyword) argument")
+        if kwargs:
+            update1(d, kwargs)
+
     def popitem(d):
         k = d.keys()
         if not k:
@@ -110,7 +118,7 @@
 ''', filename=__file__)
 #XXX what about dict.fromkeys()?
 
-dict_update__ANY_ANY         = app.interphook("update")
+dict_update__ANY             = app.interphook("update")
 dict_popitem__ANY            = app.interphook("popitem")
 dict_get__ANY_ANY_ANY        = app.interphook("get")
 dict_setdefault__ANY_ANY_ANY = app.interphook("setdefault")
@@ -118,6 +126,7 @@
 dict_iteritems__ANY          = app.interphook("iteritems")
 dict_iterkeys__ANY           = app.interphook("iterkeys")
 dict_itervalues__ANY         = app.interphook("itervalues")
+update1                      = app.interphook("update1")
 
 register_all(vars(), globals())
 

Modified: pypy/dist/pypy/objspace/std/test/test_dictobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_dictobject.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_dictobject.py	Tue Aug 15 14:51:18 2006
@@ -245,7 +245,17 @@
         d = {}
         d.update()
         assert d == {}
-    
+
+    def test_update_kwargs(self):
+        d = {}
+        d.update(foo='bar', baz=1)
+        assert d == {'foo': 'bar', 'baz': 1}
+
+    def test_update_dict_and_kwargs(self):
+        d = {}
+        d.update({'foo': 'bar'}, baz=1)
+        assert d == {'foo': 'bar', 'baz': 1}
+
     def test_values(self):
         d = {1:2, 3:4}
         vals = d.values()



More information about the Pypy-commit mailing list