summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-03-21 20:21:00 (GMT)
committerBenjamin Peterson <benjamin@python.org>2010-03-21 20:21:00 (GMT)
commit965458931ff6fae2090fa4ddd95cb7f81ce2bcc1 (patch)
treefa762b6b42f6215204b3faf33de108845de5f35a
parent54bc22e9f333547ef6183fb79c897aeecc19db14 (diff)
downloadcpython-965458931ff6fae2090fa4ddd95cb7f81ce2bcc1.zip
cpython-965458931ff6fae2090fa4ddd95cb7f81ce2bcc1.tar.gz
cpython-965458931ff6fae2090fa4ddd95cb7f81ce2bcc1.tar.bz2
improve error message from passing inadequate number of keyword arguments #6474
Note this removes the "non-keyword" or "keyword" phrases from these messages.
-rw-r--r--Lib/test/test_extcall.py9
-rw-r--r--Misc/NEWS3
-rw-r--r--Python/ceval.c12
3 files changed, 19 insertions, 5 deletions
diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py
index 3eea121..bb922c8 100644
--- a/Lib/test/test_extcall.py
+++ b/Lib/test/test_extcall.py
@@ -270,6 +270,15 @@ the function call setup. See <http://bugs.python.org/issue2016>.
... print a,b
>>> f(**x)
1 2
+
+A obscure message:
+
+ >>> def f(a, b):
+ ... pass
+ >>> f(b=1)
+ Traceback (most recent call last):
+ ...
+ TypeError: f() takes exactly 2 arguments (1 given)
"""
import unittest
diff --git a/Misc/NEWS b/Misc/NEWS
index 895c753..f93486e 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.7 beta 1?
Core and Builtins
-----------------
+- Issue #6474: Make error message from passing an inadequate number of keyword
+ arguments to a function correct.
+
- Issue #8164: Don't allow lambda functions to have a docstring.
- Issue #3137: Don't ignore errors at startup, especially a keyboard interrupt
diff --git a/Python/ceval.c b/Python/ceval.c
index 7ce3e51..4b0ff7e 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -3055,11 +3055,10 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
if (!(co->co_flags & CO_VARARGS)) {
PyErr_Format(PyExc_TypeError,
"%.200s() takes %s %d "
- "%sargument%s (%d given)",
+ "argument%s (%d given)",
PyString_AsString(co->co_name),
defcount ? "at most" : "exactly",
co->co_argcount,
- kwcount ? "non-keyword " : "",
co->co_argcount == 1 ? "" : "s",
argcount);
goto fail;
@@ -3150,15 +3149,18 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
int m = co->co_argcount - defcount;
for (i = argcount; i < m; i++) {
if (GETLOCAL(i) == NULL) {
+ int j, given = 0;
+ for (j = 0; j < co->co_argcount; j++)
+ if (GETLOCAL(j))
+ given++;
PyErr_Format(PyExc_TypeError,
"%.200s() takes %s %d "
- "%sargument%s (%d given)",
+ "argument%s (%d given)",
PyString_AsString(co->co_name),
((co->co_flags & CO_VARARGS) ||
defcount) ? "at least"
: "exactly",
- m, kwcount ? "non-keyword " : "",
- m == 1 ? "" : "s", i);
+ m, m == 1 ? "" : "s", given);
goto fail;
}
}