Merged revisions 79205,79219,79228,79230,79232-79233,79235,79237 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r79205 | benjamin.peterson | 2010-03-21 12:34:54 -0500 (Sun, 21 Mar 2010) | 1 line

  rewrite a bit
........
  r79219 | benjamin.peterson | 2010-03-21 14:24:08 -0500 (Sun, 21 Mar 2010) | 1 line

  flatten condition
........
  r79228 | benjamin.peterson | 2010-03-21 14:35:39 -0500 (Sun, 21 Mar 2010) | 1 line

  remove pointless condition
........
  r79230 | benjamin.peterson | 2010-03-21 14:39:52 -0500 (Sun, 21 Mar 2010) | 1 line

  co_varnames is certainly a tuple, so let's not waste time finding out
........
  r79232 | benjamin.peterson | 2010-03-21 14:54:56 -0500 (Sun, 21 Mar 2010) | 1 line

  fix import
........
  r79233 | benjamin.peterson | 2010-03-21 14:56:37 -0500 (Sun, 21 Mar 2010) | 1 line

  don't write duplicate tests
........
  r79235 | benjamin.peterson | 2010-03-21 15:21:00 -0500 (Sun, 21 Mar 2010) | 4 lines

  improve error message from passing inadequate number of keyword arguments #6474

  Note this removes the "non-keyword" or "keyword" phrases from these messages.
........
  r79237 | benjamin.peterson | 2010-03-21 15:30:30 -0500 (Sun, 21 Mar 2010) | 1 line

  take into account keyword arguments when passing too many args
........
diff --git a/Python/ceval.c b/Python/ceval.c
index 4e9f77b..ae9ab47 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -3076,13 +3076,12 @@
 			if (!(co->co_flags & CO_VARARGS)) {
 				PyErr_Format(PyExc_TypeError,
 				    "%U() takes %s %d "
-				    "%spositional argument%s (%d given)",
+				    "argument%s (%d given)",
 				    co->co_name,
 				    defcount ? "at most" : "exactly",
 				    co->co_argcount,
-				    kwcount ? "non-keyword " : "",
 				    co->co_argcount == 1 ? "" : "s",
-				    argcount);
+				    argcount + kwcount);
 				goto fail;
 			}
 			n = co->co_argcount;
@@ -3116,7 +3115,7 @@
 			}
 			/* Speed hack: do raw pointer compares. As names are
 			   normally interned this should almost always hit. */
-			co_varnames = PySequence_Fast_ITEMS(co->co_varnames);
+			co_varnames = ((PyTupleObject *)(co->co_varnames))->ob_item;
 			for (j = 0;
 			     j < co->co_argcount + co->co_kwonlyargcount;
 			     j++) {
@@ -3148,10 +3147,10 @@
 					    keyword);
 					goto fail;
 				}
-				PyDict_SetItem(kwdict, keyword, value);
-				continue;
 			}
-kw_found:
+			PyDict_SetItem(kwdict, keyword, value);
+			continue;
+		  kw_found:
 			if (GETLOCAL(j) != NULL) {
 				PyErr_Format(PyExc_TypeError,
 					 "%U() got multiple "
@@ -3190,16 +3189,19 @@
 			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,
 					    "%U() takes %s %d "
-					    "%spositional argument%s "
+					    "argument%s "
 					    "(%d given)",
 					    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;
 				}
 			}
@@ -3216,14 +3218,12 @@
 			}
 		}
 	}
-	else {
-		if (argcount > 0 || kwcount > 0) {
-			PyErr_Format(PyExc_TypeError,
-				     "%U() takes no arguments (%d given)",
-				     co->co_name,
-				     argcount + kwcount);
-			goto fail;
-		}
+	else if (argcount > 0 || kwcount > 0) {
+		PyErr_Format(PyExc_TypeError,
+			     "%U() takes no arguments (%d given)",
+			     co->co_name,
+			     argcount + kwcount);
+		goto fail;
 	}
 	/* Allocate and initialize storage for cell vars, and copy free
 	   vars into frame.  This isn't too efficient right now. */