[pypy-svn] r68365 - in pypy/branch/improve-kwd-args/pypy: interpreter module/__builtin__ module/__builtin__/test module/thread objspace/std

pedronis at codespeak.net pedronis at codespeak.net
Tue Oct 13 12:06:57 CEST 2009


Author: pedronis
Date: Tue Oct 13 12:06:57 2009
New Revision: 68365

Modified:
   pypy/branch/improve-kwd-args/pypy/interpreter/argument.py
   pypy/branch/improve-kwd-args/pypy/interpreter/gateway.py
   pypy/branch/improve-kwd-args/pypy/module/__builtin__/functional.py
   pypy/branch/improve-kwd-args/pypy/module/__builtin__/test/test_functional.py
   pypy/branch/improve-kwd-args/pypy/module/thread/os_local.py
   pypy/branch/improve-kwd-args/pypy/objspace/std/proxyobject.py
Log:
(cfbolz, pedronis) fixes and cleanups



Modified: pypy/branch/improve-kwd-args/pypy/interpreter/argument.py
==============================================================================
--- pypy/branch/improve-kwd-args/pypy/interpreter/argument.py	(original)
+++ pypy/branch/improve-kwd-args/pypy/interpreter/argument.py	Tue Oct 13 12:06:57 2009
@@ -57,11 +57,14 @@
                 kwds_w[self.keywords[i]] = self.keywords_w[i]
         return self.arguments_w, kwds_w
 
+    def replace_arguments(self, args_w):
+        "Return a new Arguments with a args_w as positional arguments."
+        return Arguments(self.space, args_w, self.keywords, self.keywords_w)
+
     def prepend(self, w_firstarg): # used often
         "Return a new Arguments with a new argument inserted first."
-        return Arguments(self.space, [w_firstarg] + self.arguments_w,
-                         self.keywords, self.keywords_w)
-            
+        return self.replace_arguments([w_firstarg] + self.arguments_w)
+
     def _combine_wrapped(self, w_stararg, w_starstararg):
         "unpack the *arg and **kwd into arguments_w and keywords_w"
         # unpack the * arguments 

Modified: pypy/branch/improve-kwd-args/pypy/interpreter/gateway.py
==============================================================================
--- pypy/branch/improve-kwd-args/pypy/interpreter/gateway.py	(original)
+++ pypy/branch/improve-kwd-args/pypy/interpreter/gateway.py	Tue Oct 13 12:06:57 2009
@@ -860,22 +860,22 @@
                     if ret_w is not None: # it was RPython
                         return ret_w
             # the last argument can be an Arguments
+            w_func = self.wget(space, name)
             if not args_w:
-                args = Arguments(space, [])
+                return space.call_function(w_func)
             else:
                 args = args_w[-1]
                 assert args is not None
                 if not isinstance(args, Arguments):
-                    args = Arguments(space, list(args_w))
+                    return space.call_function(w_func, *args_w)
                 else:
-                    # ...which is merged with the previous arguments, if any
-                    if len(args_w) > 1:
-                        # XXXXXXXXX
-                        more_args_w, more_kwds_w = args.unpack()
-                        args = Arguments(space,
-                                         list(args_w[:-1]) + more_args_w,
-                                         more_kwds_w.keys(), more_kwds_w.values())
-            w_func = self.wget(space, name) 
+                    if len(args_w) == 2:
+                        return space.call_obj_args(w_func, args_w[0], args)
+                    elif len(args_w) > 2:
+                        # xxx is this used at all?
+                        # ...which is merged with the previous arguments, if any
+                        args = args.replace_arguments(list(args_w[:-1]) +
+                                                      args.arguments_w)
             return space.call_args(w_func, args)
         def get_function(space):
             w_func = self.wget(space, name) 

Modified: pypy/branch/improve-kwd-args/pypy/module/__builtin__/functional.py
==============================================================================
--- pypy/branch/improve-kwd-args/pypy/module/__builtin__/functional.py	(original)
+++ pypy/branch/improve-kwd-args/pypy/module/__builtin__/functional.py	Tue Oct 13 12:06:57 2009
@@ -103,27 +103,28 @@
 
 
 @specialize.arg(2)
-def min_max(space, arguments, implementation_of):
+def min_max(space, args, implementation_of):
     if implementation_of == "max":
         compare = space.gt
     else:
         compare = space.lt
-    # XXXXXXXXX
-    args, kwargs = arguments.unpack()
-    if len(args) > 1:
-        w_sequence = space.newtuple(args)
-    elif len(args):
-        w_sequence = args[0]
+    args_w = args.arguments_w
+    if len(args_w) > 1:
+        w_sequence = space.newtuple(args_w)
+    elif len(args_w):
+        w_sequence = args_w[0]
     else:
         msg = "%s() expects at least one argument" % (implementation_of,)
         raise OperationError(space.w_TypeError, space.wrap(msg))
-    try:
-        w_key = kwargs["key"]
-    except KeyError:
-        w_key = None
-    if len(kwargs) > 1:
-        msg = "%s() got unexpected keyword argument" % (implementation_of,)
-        raise OperationError(space.w_TypeError, space.wrap(msg))
+    w_key = None
+    kwds = args.keywords
+    if kwds:
+        if kwds[0] == "key" and len(kwds) == 1:
+            w_key = args.keywords_w[0]
+        else:
+            msg = "%s() got unexpected keyword argument" % (implementation_of,)
+            raise OperationError(space.w_TypeError, space.wrap(msg))
+
     w_iter = space.iter(w_sequence)
     w_max_item = None
     w_max_val = None

Modified: pypy/branch/improve-kwd-args/pypy/module/__builtin__/test/test_functional.py
==============================================================================
--- pypy/branch/improve-kwd-args/pypy/module/__builtin__/test/test_functional.py	(original)
+++ pypy/branch/improve-kwd-args/pypy/module/__builtin__/test/test_functional.py	Tue Oct 13 12:06:57 2009
@@ -208,3 +208,17 @@
         S = [10, 20, 30]
         assert any([x > 42 for x in S]) == False
 
+class AppTestMinMax:
+   def test_min(self):
+      assert min(1, 2) == 1
+      assert min(1, 2, key=lambda x: -x) == 2
+      assert min([1, 2, 3]) == 1
+      raises(TypeError, min, 1, 2, bar=2)
+      raises(TypeError, min, 1, 2, key=lambda x: x, bar=2)
+
+   def test_max(self):
+      assert max(1, 2) == 2
+      assert max(1, 2, key=lambda x: -x) == 1
+      assert max([1, 2, 3]) == 3
+      raises(TypeError, max, 1, 2, bar=2)
+      raises(TypeError, max, 1, 2, key=lambda x: x, bar=2)

Modified: pypy/branch/improve-kwd-args/pypy/module/thread/os_local.py
==============================================================================
--- pypy/branch/improve-kwd-args/pypy/module/thread/os_local.py	(original)
+++ pypy/branch/improve-kwd-args/pypy/module/thread/os_local.py	Tue Oct 13 12:06:57 2009
@@ -12,7 +12,7 @@
 
     def __init__(self, space, initargs):
         self.space = space
-        self.initargs = initargs.normalize()
+        self.initargs = initargs
         ident = thread.get_ident()
         self.dicts = {ident: space.newdict()}
 

Modified: pypy/branch/improve-kwd-args/pypy/objspace/std/proxyobject.py
==============================================================================
--- pypy/branch/improve-kwd-args/pypy/objspace/std/proxyobject.py	(original)
+++ pypy/branch/improve-kwd-args/pypy/objspace/std/proxyobject.py	Tue Oct 13 12:06:57 2009
@@ -22,11 +22,9 @@
             self.space = space
     
         def descr_call_mismatch(self, space, name, reqcls, args):
-            # xxx fishing
             args_w = args.arguments_w[:]
             args_w[0] = space.wrap(name)
-            args = argument.Arguments(space, args_w,  args.keywords,
-                                                      args.keywords_w)
+            args = args.replace_arguments(args_w)
             return space.call_args(self.w_controller, args)
     
         def getclass(self, space):



More information about the Pypy-commit mailing list