Commits

Armin Rigo committed 611fa0c

Use the same keyword arguments as CPython for constructing built-in types,
e.g. int(x=5).

  • Participants
  • Parent commits 8edb645

Comments (0)

Files changed (6)

pypy/objspace/std/fake.py

 
     kw['__module__'] = cpy_type.__module__
 
-    def fake__new__(space, w_type, args_w):
+    def fake__new__(space, w_type, __args__):
+        args_w, kwds_w = __args__.unpack()
         args = [space.unwrap(w_arg) for w_arg in args_w]
+        kwds = dict([(key, space.unwrap(w_value))
+                     for (key, w_value) in kwds_w.items()])
         try:
-            r = cpy_type.__new__(cpy_type, *args)
+            r = cpy_type.__new__(cpy_type, *args, **kwds)
         except:
             wrap_exception(space)
             raise
     kw['__new__'] = gateway.interp2app(fake__new__,
                          unwrap_spec = [baseobjspace.ObjSpace,
                                         baseobjspace.W_Root,
-                                        'args_w'])
+                                        gateway.Arguments])
     if cpy_type.__base__ is not object:
         assert cpy_type.__base__ is basestring
         from pypy.objspace.std.basestringtype import basestring_typedef

pypy/objspace/std/floattype.py

 from pypy.objspace.std.stdtypedef import *
 from pypy.interpreter.error import OperationError
 
-def descr__new__(space, w_floattype, w_value=0.0):
+def descr__new__(space, w_floattype, w_x=0.0):
     from pypy.objspace.std.floatobject import W_FloatObject
+    w_value = w_x     # 'x' is the keyword argument name in CPython
     if space.is_true(space.isinstance(w_value, space.w_str)):
         try:
             value = float(space.str_w(w_value))

pypy/objspace/std/inttype.py

         raise OperationError(space.w_ValueError,
                              space.wrap(e.msg))
     
-def descr__new__(space, w_inttype, w_value=0, w_base=NoneNotWrapped):
+def descr__new__(space, w_inttype, w_x=0, w_base=NoneNotWrapped):
     from pypy.objspace.std.intobject import W_IntObject
     w_longval = None
+    w_value = w_x     # 'x' is the keyword argument name in CPython
     value = 0
     if w_base is None:
         # check for easy cases

pypy/objspace/std/longtype.py

 from pypy.interpreter.gateway import NoneNotWrapped
 from pypy.rpython.rarithmetic import r_uint
 
-def descr__new__(space, w_longtype, w_value=0, w_base=NoneNotWrapped):
+def descr__new__(space, w_longtype, w_x=0, w_base=NoneNotWrapped):
     from pypy.objspace.std.longobject import W_LongObject, args_from_long
+    w_value = w_x     # 'x' is the keyword argument name in CPython
     if w_base is None:
         # check for easy cases
         if isinstance(w_value, W_LongObject):

pypy/objspace/std/stringtype.py

 
 # ____________________________________________________________
 
-def descr__new__(space, w_stringtype, w_obj=''):
+def descr__new__(space, w_stringtype, w_object=''):
     from pypy.objspace.std.stringobject import W_StringObject
-    w_obj = space.str(w_obj)
+    w_obj = space.str(w_object)
     if space.is_true(space.is_(w_stringtype, space.w_str)):
         return w_obj  # XXX might be reworked when space.str() typechecks
     value = space.str_w(w_obj)

pypy/objspace/std/tupletype.py

 from pypy.objspace.std.stdtypedef import *
 from pypy.interpreter.gateway import NoneNotWrapped
 
-def descr__new__(space, w_tupletype, w_items=NoneNotWrapped):
+def descr__new__(space, w_tupletype, w_sequence=NoneNotWrapped):
     from pypy.objspace.std.tupleobject import W_TupleObject
-    if w_items is None:
+    if w_sequence is None:
         tuple_w = []
     elif (space.is_w(w_tupletype, space.w_tuple) and
-          space.is_w(space.type(w_items), space.w_tuple)):
-        return w_items
+          space.is_w(space.type(w_sequence), space.w_tuple)):
+        return w_sequence
     else:
-        tuple_w = space.unpackiterable(w_items)
+        tuple_w = space.unpackiterable(w_sequence)
     w_obj = space.allocate_instance(W_TupleObject, w_tupletype)
     W_TupleObject.__init__(w_obj, space, tuple_w)
     return w_obj