mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-31229: Fixed wrong error messages when too many keyword arguments are received. (#3180)
This commit is contained in:
parent
772d809a63
commit
bf9075a0c5
2 changed files with 29 additions and 2 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue