[Python-checkins] r79235 - in python/trunk: Lib/test/test_extcall.py Misc/NEWS Python/ceval.c
benjamin.peterson
python-checkins at python.org
Sun Mar 21 21:21:00 CET 2010
Author: benjamin.peterson
Date: Sun Mar 21 21:21:00 2010
New Revision: 79235
Log:
improve error message from passing inadequate number of keyword arguments #6474
Note this removes the "non-keyword" or "keyword" phrases from these messages.
Modified:
python/trunk/Lib/test/test_extcall.py
python/trunk/Misc/NEWS
python/trunk/Python/ceval.c
Modified: python/trunk/Lib/test/test_extcall.py
==============================================================================
--- python/trunk/Lib/test/test_extcall.py (original)
+++ python/trunk/Lib/test/test_extcall.py Sun Mar 21 21:21:00 2010
@@ -270,6 +270,15 @@
... 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
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Sun Mar 21 21:21:00 2010
@@ -12,6 +12,9 @@
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
Modified: python/trunk/Python/ceval.c
==============================================================================
--- python/trunk/Python/ceval.c (original)
+++ python/trunk/Python/ceval.c Sun Mar 21 21:21:00 2010
@@ -3055,11 +3055,10 @@
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 @@
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;
}
}
More information about the Python-checkins
mailing list