parse((1, 2, 3), {}, b'OOO', ['', '', 'a'])
parse((1, 2), {'a': 3}, b'OOO', ['', '', 'a'])
with self.assertRaisesRegex(TypeError,
- r'Function takes at least 2 positional arguments \(1 given\)'):
+ r'function takes at least 2 positional arguments \(1 given\)'):
parse((1,), {'a': 3}, b'OOO', ['', '', 'a'])
parse((1,), {}, b'O|OO', ['', '', 'a'])
with self.assertRaisesRegex(TypeError,
- r'Function takes at least 1 positional arguments \(0 given\)'):
+ r'function takes at least 1 positional arguments \(0 given\)'):
parse((), {}, b'O|OO', ['', '', 'a'])
parse((1, 2), {'a': 3}, b'OO$O', ['', '', 'a'])
with self.assertRaisesRegex(TypeError,
- r'Function takes exactly 2 positional arguments \(1 given\)'):
+ r'function takes exactly 2 positional arguments \(1 given\)'):
parse((1,), {'a': 3}, b'OO$O', ['', '', 'a'])
parse((1,), {}, b'O|O$O', ['', '', 'a'])
with self.assertRaisesRegex(TypeError,
- r'Function takes at least 1 positional arguments \(0 given\)'):
+ r'function takes at least 1 positional arguments \(0 given\)'):
parse((), {}, b'O|O$O', ['', '', 'a'])
with self.assertRaisesRegex(SystemError, r'Empty parameter name after \$'):
parse((1,), {}, b'O|$OO', ['', '', 'a'])
try:
getargs_keywords(arg1=(1,2))
except TypeError as err:
- self.assertEqual(str(err), "Required argument 'arg2' (pos 2) not found")
+ self.assertEqual(
+ str(err), "function missing required argument 'arg2' (pos 2)")
else:
self.fail('TypeError should have been raised')
)
# required arg missing
with self.assertRaisesRegex(TypeError,
- r"Required argument 'required' \(pos 1\) not found"):
+ r"function missing required argument 'required' \(pos 1\)"):
getargs_keyword_only(optional=2)
with self.assertRaisesRegex(TypeError,
- r"Required argument 'required' \(pos 1\) not found"):
+ r"function missing required argument 'required' \(pos 1\)"):
getargs_keyword_only(keyword_only=3)
def test_too_many_args(self):
with self.assertRaisesRegex(TypeError,
- r"Function takes at most 2 positional arguments \(3 given\)"):
+ r"function takes at most 2 positional arguments \(3 given\)"):
getargs_keyword_only(1, 2, 3)
with self.assertRaisesRegex(TypeError,
self.assertEqual(self.getargs(1), (1, -1, -1))
# required positional arg missing
with self.assertRaisesRegex(TypeError,
- r"Function takes at least 1 positional arguments \(0 given\)"):
+ r"function takes at least 1 positional arguments \(0 given\)"):
self.getargs()
with self.assertRaisesRegex(TypeError,
- r"Function takes at least 1 positional arguments \(0 given\)"):
+ r"function takes at least 1 positional arguments \(0 given\)"):
self.getargs(keyword=3)
def test_empty_keyword(self):
}
if (!_PyDict_HasOnlyStringKeys(kwargs)) {
PyErr_SetString(PyExc_TypeError,
- "keyword arguments must be strings");
+ "keywords must be strings");
return 0;
}
return 1;
nkwargs = (kwargs == NULL) ? 0 : PyDict_GET_SIZE(kwargs);
if (nargs + nkwargs > len) {
PyErr_Format(PyExc_TypeError,
- "%s%s takes at most %d argument%s (%zd given)",
+ "%.200s%s takes at most %d argument%s (%zd given)",
(fname == NULL) ? "function" : fname,
(fname == NULL) ? "" : "()",
len,
}
if (max < nargs) {
PyErr_Format(PyExc_TypeError,
- "Function takes %s %d positional arguments"
+ "%.200s%s takes %s %d positional arguments"
" (%d given)",
+ (fname == NULL) ? "function" : fname,
+ (fname == NULL) ? "" : "()",
(min != INT_MAX) ? "at most" : "exactly",
max, nargs);
return cleanreturn(0, &freelist);
* or the end of the format. */
}
else {
- PyErr_Format(PyExc_TypeError, "Required argument "
- "'%s' (pos %d) not found",
+ PyErr_Format(PyExc_TypeError, "%.200s%s missing required "
+ "argument '%s' (pos %d)",
+ (fname == NULL) ? "function" : fname,
+ (fname == NULL) ? "" : "()",
kwlist[i], i+1);
return cleanreturn(0, &freelist);
}
if (skip) {
PyErr_Format(PyExc_TypeError,
- "Function takes %s %d positional arguments"
+ "%.200s%s takes %s %d positional arguments"
" (%d given)",
+ (fname == NULL) ? "function" : fname,
+ (fname == NULL) ? "" : "()",
(Py_MIN(pos, min) < i) ? "at least" : "exactly",
Py_MIN(pos, min), nargs);
return cleanreturn(0, &freelist);
if (current_arg) {
/* arg present in tuple and in dict */
PyErr_Format(PyExc_TypeError,
- "Argument given by name ('%s') "
+ "argument for %.200s%s given by name ('%s') "
"and position (%d)",
+ (fname == NULL) ? "function" : fname,
+ (fname == NULL) ? "" : "()",
kwlist[i], i+1);
return cleanreturn(0, &freelist);
}
if (!match) {
PyErr_Format(PyExc_TypeError,
"'%U' is an invalid keyword "
- "argument for this function",
- key);
+ "argument for %.200s%s",
+ key,
+ (fname == NULL) ? "this function" : fname,
+ (fname == NULL) ? "" : "()");
return cleanreturn(0, &freelist);
}
}
}
if (nargs + nkwargs > len) {
PyErr_Format(PyExc_TypeError,
- "%s%s takes at most %d argument%s (%zd given)",
+ "%.200s%s takes at most %d argument%s (%zd given)",
(parser->fname == NULL) ? "function" : parser->fname,
(parser->fname == NULL) ? "" : "()",
len,
}
if (parser->max < nargs) {
PyErr_Format(PyExc_TypeError,
- "Function takes %s %d positional arguments (%d given)",
+ "%200s%s takes %s %d positional arguments (%d given)",
+ (parser->fname == NULL) ? "function" : parser->fname,
+ (parser->fname == NULL) ? "" : "()",
(parser->min != INT_MAX) ? "at most" : "exactly",
parser->max, nargs);
return cleanreturn(0, &freelist);
if (i < pos) {
Py_ssize_t min = Py_MIN(pos, parser->min);
PyErr_Format(PyExc_TypeError,
- "Function takes %s %d positional arguments"
+ "%.200s%s takes %s %d positional arguments"
" (%d given)",
+ (parser->fname == NULL) ? "function" : parser->fname,
+ (parser->fname == NULL) ? "" : "()",
min < parser->max ? "at least" : "exactly",
min, nargs);
}
else {
keyword = PyTuple_GET_ITEM(kwtuple, i - pos);
- PyErr_Format(PyExc_TypeError, "Required argument "
- "'%U' (pos %d) not found",
+ PyErr_Format(PyExc_TypeError, "%.200s%s missing required "
+ "argument '%U' (pos %d)",
+ (parser->fname == NULL) ? "function" : parser->fname,
+ (parser->fname == NULL) ? "" : "()",
keyword, i+1);
}
return cleanreturn(0, &freelist);
if (current_arg) {
/* arg present in tuple and in dict */
PyErr_Format(PyExc_TypeError,
- "Argument given by name ('%U') "
+ "argument for %.200s%s given by name ('%U') "
"and position (%d)",
+ (parser->fname == NULL) ? "function" : parser->fname,
+ (parser->fname == NULL) ? "" : "()",
keyword, i+1);
return cleanreturn(0, &freelist);
}
if (!match) {
PyErr_Format(PyExc_TypeError,
"'%U' is an invalid keyword "
- "argument for this function",
- keyword);
+ "argument for %.200s%s",
+ keyword,
+ (parser->fname == NULL) ? "this function" : parser->fname,
+ (parser->fname == NULL) ? "" : "()");
}
return cleanreturn(0, &freelist);
}
if (name != NULL)
PyErr_Format(
PyExc_TypeError,
- "%s expected %s%zd arguments, got %zd",
+ "%.200s expected %s%zd arguments, got %zd",
name, (min == max ? "" : "at least "), min, nargs);
else
PyErr_Format(
if (name != NULL)
PyErr_Format(
PyExc_TypeError,
- "%s expected %s%zd arguments, got %zd",
+ "%.200s expected %s%zd arguments, got %zd",
name, (min == max ? "" : "at most "), max, nargs);
else
PyErr_Format(
return 1;
}
- PyErr_Format(PyExc_TypeError, "%s does not take keyword arguments",
+ PyErr_Format(PyExc_TypeError, "%.200s does not take keyword arguments",
funcname);
return 0;
}
return 1;
}
- PyErr_Format(PyExc_TypeError, "%s does not take keyword arguments",
+ PyErr_Format(PyExc_TypeError, "%.200s does not take keyword arguments",
funcname);
return 0;
}
if (PyTuple_GET_SIZE(args) == 0)
return 1;
- PyErr_Format(PyExc_TypeError, "%s does not take positional arguments",
+ PyErr_Format(PyExc_TypeError, "%.200s does not take positional arguments",
funcname);
return 0;
}