[pypy-commit] pypy py3k: Fixes the combined use of kwonly arguments and default parameters
rguillebert
noreply at buildbot.pypy.org
Sun Jan 22 10:58:15 CET 2012
Author: Romain Guillebert <romain.py at gmail.com>
Branch: py3k
Changeset: r51628:99083d2bfef1
Date: 2012-01-22 10:57 +0100
http://bitbucket.org/pypy/pypy/changeset/99083d2bfef1/
Log: Fixes the combined use of kwonly arguments and default parameters
diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -35,6 +35,9 @@
def num_argnames(self):
return len(self.argnames)
+ def num_kwonlyargnames(self):
+ return len(self.kwonlyargnames)
+
def has_vararg(self):
return self.varargname is not None
@@ -291,6 +294,7 @@
# so all values coming from there can be assumed constant. It assumes
# that the length of the defaults_w does not vary too much.
co_argcount = signature.num_argnames() # expected formal arguments, without */**
+ co_kwonlyargcount = signature.num_kwonlyargnames()
has_vararg = signature.has_vararg()
has_kwarg = signature.has_kwarg()
extravarargs = None
@@ -379,9 +383,9 @@
used_keywords[i] = True # mark as used
num_remainingkwds -= 1
missing = 0
- if input_argcount < co_argcount:
- def_first = co_argcount - (0 if defaults_w is None else len(defaults_w))
- for i in range(input_argcount, co_argcount):
+ if input_argcount < co_argcount + co_kwonlyargcount:
+ def_first = co_argcount + co_kwonlyargcount - (0 if defaults_w is None else len(defaults_w))
+ for i in range(input_argcount, co_argcount + co_kwonlyargcount):
if scope_w[i] is not None:
continue
defnum = i - def_first
@@ -393,6 +397,10 @@
# keyword arguments, which will be checked for below.
missing += 1
+ # TODO: Put a nice error message
+ #if co_kwonlyargcount:
+ # assert co_kwonlyargcount == len(signature.kwonlyargnames)
+
# collect extra keyword arguments into the **kwarg
if has_kwarg:
w_kwds = self.space.newdict()
@@ -423,7 +431,7 @@
co_argcount, has_vararg, has_kwarg,
defaults_w, missing)
- return co_argcount + has_vararg + has_kwarg
+ return co_argcount + has_vararg + has_kwarg + co_kwonlyargcount
diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -106,6 +106,7 @@
if self.co_cellvars:
argcount = self.co_argcount
+ argcount += self.co_kwonlyargcount
assert argcount >= 0 # annotator hint
if self.co_flags & CO_VARARGS:
argcount += 1
@@ -208,6 +209,8 @@
return
if len(self._args_as_cellvars) > 0:
return
+ if self.co_kwonlyargcount > 0:
+ return
if self.co_argcount > 0xff:
return
More information about the pypy-commit
mailing list