comparison Python/ceval.c @ 59857:ec6a995ecfbf

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 ........
author Benjamin Peterson <benjamin@python.org>
date Sun, 21 Mar 2010 21:00:50 +0000
parents f49d24b4456e
children 48f40a1785ca
comparison
equal deleted inserted replaced
59839:c694618dab54 59857:ec6a995ecfbf
3074 } 3074 }
3075 if (argcount > co->co_argcount) { 3075 if (argcount > co->co_argcount) {
3076 if (!(co->co_flags & CO_VARARGS)) { 3076 if (!(co->co_flags & CO_VARARGS)) {
3077 PyErr_Format(PyExc_TypeError, 3077 PyErr_Format(PyExc_TypeError,
3078 "%U() takes %s %d " 3078 "%U() takes %s %d "
3079 "%spositional argument%s (%d given)", 3079 "argument%s (%d given)",
3080 co->co_name, 3080 co->co_name,
3081 defcount ? "at most" : "exactly", 3081 defcount ? "at most" : "exactly",
3082 co->co_argcount, 3082 co->co_argcount,
3083 kwcount ? "non-keyword " : "",
3084 co->co_argcount == 1 ? "" : "s", 3083 co->co_argcount == 1 ? "" : "s",
3085 argcount); 3084 argcount + kwcount);
3086 goto fail; 3085 goto fail;
3087 } 3086 }
3088 n = co->co_argcount; 3087 n = co->co_argcount;
3089 } 3088 }
3090 for (i = 0; i < n; i++) { 3089 for (i = 0; i < n; i++) {
3114 co->co_name); 3113 co->co_name);
3115 goto fail; 3114 goto fail;
3116 } 3115 }
3117 /* Speed hack: do raw pointer compares. As names are 3116 /* Speed hack: do raw pointer compares. As names are
3118 normally interned this should almost always hit. */ 3117 normally interned this should almost always hit. */
3119 co_varnames = PySequence_Fast_ITEMS(co->co_varnames); 3118 co_varnames = ((PyTupleObject *)(co->co_varnames))->ob_item;
3120 for (j = 0; 3119 for (j = 0;
3121 j < co->co_argcount + co->co_kwonlyargcount; 3120 j < co->co_argcount + co->co_kwonlyargcount;
3122 j++) { 3121 j++) {
3123 PyObject *nm = co_varnames[j]; 3122 PyObject *nm = co_varnames[j];
3124 if (nm == keyword) 3123 if (nm == keyword)
3146 "keyword argument '%S'", 3145 "keyword argument '%S'",
3147 co->co_name, 3146 co->co_name,
3148 keyword); 3147 keyword);
3149 goto fail; 3148 goto fail;
3150 } 3149 }
3151 PyDict_SetItem(kwdict, keyword, value); 3150 }
3152 continue; 3151 PyDict_SetItem(kwdict, keyword, value);
3153 } 3152 continue;
3154 kw_found: 3153 kw_found:
3155 if (GETLOCAL(j) != NULL) { 3154 if (GETLOCAL(j) != NULL) {
3156 PyErr_Format(PyExc_TypeError, 3155 PyErr_Format(PyExc_TypeError,
3157 "%U() got multiple " 3156 "%U() got multiple "
3158 "values for keyword " 3157 "values for keyword "
3159 "argument '%S'", 3158 "argument '%S'",
3188 } 3187 }
3189 if (argcount < co->co_argcount) { 3188 if (argcount < co->co_argcount) {
3190 int m = co->co_argcount - defcount; 3189 int m = co->co_argcount - defcount;
3191 for (i = argcount; i < m; i++) { 3190 for (i = argcount; i < m; i++) {
3192 if (GETLOCAL(i) == NULL) { 3191 if (GETLOCAL(i) == NULL) {
3192 int j, given = 0;
3193 for (j = 0; j < co->co_argcount; j++)
3194 if (GETLOCAL(j))
3195 given++;
3193 PyErr_Format(PyExc_TypeError, 3196 PyErr_Format(PyExc_TypeError,
3194 "%U() takes %s %d " 3197 "%U() takes %s %d "
3195 "%spositional argument%s " 3198 "argument%s "
3196 "(%d given)", 3199 "(%d given)",
3197 co->co_name, 3200 co->co_name,
3198 ((co->co_flags & CO_VARARGS) || 3201 ((co->co_flags & CO_VARARGS) ||
3199 defcount) ? "at least" 3202 defcount) ? "at least"
3200 : "exactly", 3203 : "exactly",
3201 m, kwcount ? "non-keyword " : "", 3204 m, m == 1 ? "" : "s", given);
3202 m == 1 ? "" : "s", i);
3203 goto fail; 3205 goto fail;
3204 } 3206 }
3205 } 3207 }
3206 if (n > m) 3208 if (n > m)
3207 i = n - m; 3209 i = n - m;
3214 SETLOCAL(m+i, def); 3216 SETLOCAL(m+i, def);
3215 } 3217 }
3216 } 3218 }
3217 } 3219 }
3218 } 3220 }
3219 else { 3221 else if (argcount > 0 || kwcount > 0) {
3220 if (argcount > 0 || kwcount > 0) { 3222 PyErr_Format(PyExc_TypeError,
3221 PyErr_Format(PyExc_TypeError, 3223 "%U() takes no arguments (%d given)",
3222 "%U() takes no arguments (%d given)", 3224 co->co_name,
3223 co->co_name, 3225 argcount + kwcount);
3224 argcount + kwcount); 3226 goto fail;
3225 goto fail;
3226 }
3227 } 3227 }
3228 /* Allocate and initialize storage for cell vars, and copy free 3228 /* Allocate and initialize storage for cell vars, and copy free
3229 vars into frame. This isn't too efficient right now. */ 3229 vars into frame. This isn't too efficient right now. */
3230 if (PyTuple_GET_SIZE(co->co_cellvars)) { 3230 if (PyTuple_GET_SIZE(co->co_cellvars)) {
3231 int i, j, nargs, found; 3231 int i, j, nargs, found;