Author: Benjamin Peterson <[email protected]>
Branch: py3k
Changeset: r53639:9e4771718600
Date: 2012-03-14 21:24 -0500
http://bitbucket.org/pypy/pypy/changeset/9e4771718600/

Log:    put varnames in the same order as cpython

diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -27,8 +27,7 @@
         except ValueError:
             pass
         try:
-            return (len(self.argnames) + self.has_vararg() +
-                    self.kwonlyargnames.index(name))
+            return len(self.argnames) + self.kwonlyargnames.index(name)
         except ValueError:
             pass
         return -1
@@ -347,7 +346,8 @@
                 starargs_w = args_w[args_left:]
             else:
                 starargs_w = []
-            scope_w[co_argcount] = self.space.newtuple(starargs_w)
+            loc = co_argcount + co_kwonlyargcount
+            scope_w[loc] = self.space.newtuple(starargs_w)
         elif avail > co_argcount:
             raise ArgErrCount(avail, num_kwds,
                               co_argcount, has_vararg, has_kwarg,
diff --git a/pypy/interpreter/astcompiler/symtable.py 
b/pypy/interpreter/astcompiler/symtable.py
--- a/pypy/interpreter/astcompiler/symtable.py
+++ b/pypy/interpreter/astcompiler/symtable.py
@@ -494,11 +494,11 @@
         assert isinstance(scope, FunctionScope) # Annotator hint.
         if arguments.args:
             self._handle_params(arguments.args, True)
+        if arguments.kwonlyargs:
+            self._handle_params(arguments.kwonlyargs, True)
         if arguments.vararg:
             self.note_symbol(arguments.vararg, SYM_PARAM)
             scope.note_variable_arg(arguments.vararg)
-        if arguments.kwonlyargs:
-            self._handle_params(arguments.kwonlyargs, True)
         if arguments.kwarg:
             self.note_symbol(arguments.kwarg, SYM_PARAM)
             scope.note_keywords_arg(arguments.kwarg)
diff --git a/pypy/interpreter/astcompiler/test/test_symtable.py 
b/pypy/interpreter/astcompiler/test/test_symtable.py
--- a/pypy/interpreter/astcompiler/test/test_symtable.py
+++ b/pypy/interpreter/astcompiler/test/test_symtable.py
@@ -139,10 +139,12 @@
 
     def test_arguments_kwonly(self):
         scp = self.func_scope("def f(a, *b, c, **d): pass")
-        varnames = ["a", "b", "c", "d"]
+        varnames = ["a", "c", "b", "d"]
         for name in varnames:
             assert scp.lookup(name) == symtable.SCOPE_LOCAL
         assert scp.varnames == varnames
+        scp = self.func_scope("def f(a, b=0, *args, k1, k2=0): pass")
+        assert scp.varnames == ["a", "b", "k1", "k2", "args"]
 
     def test_function(self):
         scp = self.func_scope("def f(): x = 4")
diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -50,12 +50,12 @@
     assert argcount >= 0     # annotator hint
     assert kwonlyargcount >= 0
     argnames = list(code.co_varnames[:argcount])
+    kwonlyargs = list(code.co_varnames[argcount:argcount + kwonlyargcount])
     if code.co_flags & CO_VARARGS:
         varargname = code.co_varnames[argcount]
         argcount += 1
     else:
         varargname = None
-    kwonlyargs = list(code.co_varnames[argcount:argcount + kwonlyargcount])
     if code.co_flags & CO_VARKEYWORDS:
         kwargname = code.co_varnames[argcount]
         argcount += 1
diff --git a/pypy/interpreter/test/test_interpreter.py 
b/pypy/interpreter/test/test_interpreter.py
--- a/pypy/interpreter/test/test_interpreter.py
+++ b/pypy/interpreter/test/test_interpreter.py
@@ -333,3 +333,11 @@
             assert str(e) == "maximum recursion depth exceeded"
         else:
             assert 0, "should have raised!"
+
+    def test_kwonlyargs_mixed_args(self):
+        """
+        def mixedargs_sum(a, b=0, *args, k1, k2=0):
+            return a + b + k1 + k2 + sum(args)
+        assert mixedargs_sum.__code__.co_varnames == ("a", "b", "k1", "k2", 
"args")
+        assert mixedargs_sum(1, k1=2) == 1 + 2
+        """
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to