diff options
author | Oren Milman <orenmn@gmail.com> | 2017-08-23 18:16:48 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-08-23 18:16:48 (GMT) |
commit | bf9075a0c55186d2f34df63e6c8512dd6414ff4b (patch) | |
tree | b2a84f87f0a22a086ea282d2c6b99f3234b6003b /Python | |
parent | 772d809a63f40fd35679da3fb115cdf7fa81bd20 (diff) | |
download | cpython-bf9075a0c55186d2f34df63e6c8512dd6414ff4b.zip cpython-bf9075a0c55186d2f34df63e6c8512dd6414ff4b.tar.gz cpython-bf9075a0c55186d2f34df63e6c8512dd6414ff4b.tar.bz2 |
bpo-31229: Fixed wrong error messages when too many keyword arguments are received. (#3180)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/getargs.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Python/getargs.c b/Python/getargs.c index 4645b0f..4b969d9 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -1654,11 +1654,14 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format, nargs = PyTuple_GET_SIZE(args); nkwargs = (kwargs == NULL) ? 0 : PyDict_GET_SIZE(kwargs); if (nargs + nkwargs > len) { + /* Adding "keyword" (when nargs == 0) prevents producing wrong error + messages in some special cases (see bpo-31229). */ PyErr_Format(PyExc_TypeError, - "%.200s%s takes at most %d argument%s (%zd given)", + "%.200s%s takes at most %d %sargument%s (%zd given)", (fname == NULL) ? "function" : fname, (fname == NULL) ? "" : "()", len, + (nargs == 0) ? "keyword " : "", (len == 1) ? "" : "s", nargs + nkwargs); return cleanreturn(0, &freelist); @@ -2077,11 +2080,14 @@ vgetargskeywordsfast_impl(PyObject **args, Py_ssize_t nargs, nkwargs = 0; } if (nargs + nkwargs > len) { + /* Adding "keyword" (when nargs == 0) prevents producing wrong error + messages in some special cases (see bpo-31229). */ PyErr_Format(PyExc_TypeError, - "%.200s%s takes at most %d argument%s (%zd given)", + "%.200s%s takes at most %d %sargument%s (%zd given)", (parser->fname == NULL) ? "function" : parser->fname, (parser->fname == NULL) ? "" : "()", len, + (nargs == 0) ? "keyword " : "", (len == 1) ? "" : "s", nargs + nkwargs); return cleanreturn(0, &freelist); |