[pypy-svn] rev 748 - pypy/trunk/src/pypy/objspace/std

arigo at codespeak.net arigo at codespeak.net
Mon Jun 2 15:40:13 CEST 2003


Author: arigo
Date: Mon Jun  2 15:40:13 2003
New Revision: 748

Modified:
   pypy/trunk/src/pypy/objspace/std/listtype.py
   pypy/trunk/src/pypy/objspace/std/multimethod.py
   pypy/trunk/src/pypy/objspace/std/stringobject.py
   pypy/trunk/src/pypy/objspace/std/stringtype.py
   pypy/trunk/src/pypy/objspace/std/typeobject.py
Log:
object methods can now have (simple) default values

Modified: pypy/trunk/src/pypy/objspace/std/listtype.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/listtype.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/listtype.py	Mon Jun  2 15:40:13 2003
@@ -9,7 +9,7 @@
     list_append = MultiMethod('append', 2)
     list_insert = MultiMethod('insert', 3)
     list_extend = MultiMethod('extend', 2)
-    list_pop    = MultiMethod('pop',    2)
+    list_pop    = MultiMethod('pop',    2, defaults=(-1,))
     list_remove = MultiMethod('remove', 2)
     list_index  = MultiMethod('index',  2)
     list_count  = MultiMethod('count',  2)

Modified: pypy/trunk/src/pypy/objspace/std/multimethod.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/multimethod.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/multimethod.py	Mon Jun  2 15:40:13 2003
@@ -9,7 +9,7 @@
 
     ASSERT_BASE_TYPE = None
 
-    def __init__(self, operatorsymbol, arity, specialnames=None):
+    def __init__(self, operatorsymbol, arity, specialnames=None, defaults=()):
         "MultiMethod dispatching on the first 'arity' arguments."
         self.arity = arity
         self.operatorsymbol = operatorsymbol
@@ -17,6 +17,7 @@
         if specialnames is None:
             specialnames = [operatorsymbol]
         self.specialnames = specialnames  # list like ['__xxx__', '__rxxx__']
+        self.defaults = defaults
         self.cache_dependencies = {}
         self.cache_table = {}
 

Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/stringobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/stringobject.py	Mon Jun  2 15:40:13 2003
@@ -307,7 +307,7 @@
         r[i] = space.getitem(w_str, w(start + i*step))
     w_r = space.newlist(r)
     w_empty = space.newstring([])
-    return str_join(w_empty, w_r)
+    return str_join(space, w_empty, w_r)
 
 StdObjSpace.getitem.register(getitem_str_slice, 
                              W_StringObject, W_SliceObject)

Modified: pypy/trunk/src/pypy/objspace/std/stringtype.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/stringtype.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/stringtype.py	Mon Jun  2 15:40:13 2003
@@ -7,7 +7,7 @@
     typename = 'str'
 
     str_join    = MultiMethod('join', 2)
-    str_split   = MultiMethod('split', 2)
+    str_split   = MultiMethod('split', 2, defaults=(None,))
 
     str_isdigit = MultiMethod('isdigit', 1)
     str_isalpha = MultiMethod('isalpha', 1)

Modified: pypy/trunk/src/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/typeobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/typeobject.py	Mon Jun  2 15:40:13 2003
@@ -64,7 +64,7 @@
             raise KeyError   # pass on the KeyError
         if code.slice().is_empty():
             raise KeyError
-        return space.newfunction(code, space.w_None, space.w_None)
+        return space.newfunction(code, space.w_None, code.getdefaults(space))
 
     def acceptclass(w_self, cls):
         # For multimethod slicing. This checks whether a Python object of
@@ -106,6 +106,9 @@
         self.bound_position = bound_position
         self.w_type = w_type
 
+    def getdefaults(self, space):
+        return space.wrap(self.basemultimethod.defaults)
+
     def cleardependency(self):
         # called when the underlying dispatch table is modified
         self.slicedmultimethod = None


More information about the Pypy-commit mailing list