Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
Address Serhiy's review
- try to make the error message even clearer

- sync with PyArg_Parse
  • Loading branch information
erlend-aasland committed Apr 5, 2024
commit fe02eddf96e9b03d4b16a2da67883fe312eb43f1
5 changes: 3 additions & 2 deletions Lib/test/clinic.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,8 @@ test_int_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
}
if (PyUnicode_GET_LENGTH(args[2]) != 1) {
PyErr_SetString(PyExc_TypeError,
"test_int_converter(): argument 3 must be exactly one character long");
"test_int_converter(): argument 3 must be a string containing "
"exactly one unicode character");
goto exit;
}
c = PyUnicode_READ_CHAR(args[2], 0);
Expand All @@ -1049,7 +1050,7 @@ test_int_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)

static PyObject *
test_int_converter_impl(PyObject *module, int a, int b, int c, myenum d)
/*[clinic end generated code: output=fd8e758049e1d836 input=d20541fc1ca0553e]*/
/*[clinic end generated code: output=9c44e10850d9b44c input=d20541fc1ca0553e]*/


/*[clinic input]
Expand Down
5 changes: 3 additions & 2 deletions Modules/clinic/_testclinic.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Modules/clinic/arraymodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 21 additions & 11 deletions Modules/clinic/unicodedata.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions PC/clinic/msvcrtmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Python/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,11 +575,13 @@ static const char *
converterr(const char *expected, PyObject *arg, char *msgbuf, size_t bufsize)
{
assert(expected != NULL);
assert(arg != NULL);
if (expected[0] == '(') {
PyOS_snprintf(msgbuf, bufsize,
"%.100s", expected);
}
else if (arg == NULL} {
PyOS_snprintf(msgbuf, bufsize, "must be %.100s", expected);
}
else {
PyOS_snprintf(msgbuf, bufsize,
"must be %.50s, not %.50s", expected,
Expand Down Expand Up @@ -812,7 +814,8 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
return converterr("a unicode character", arg, msgbuf, bufsize);

if (PyUnicode_GET_LENGTH(arg) != 1)
return converterr("a unicode character", arg, msgbuf, bufsize);
return converterr("a string containing exactly one unicode character",
NULL, msgbuf, bufsize);

kind = PyUnicode_KIND(arg);
data = PyUnicode_DATA(arg);
Expand Down
3 changes: 2 additions & 1 deletion Tools/clinic/libclinic/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> st
}}}}
if (PyUnicode_GET_LENGTH({argname}) != 1) {{{{
PyErr_SetString(PyExc_TypeError,
"{{name}}(): {displayname} must be exactly one character long");
"{{name}}(): {displayname} must be a string containing "
"exactly one unicode character");
goto exit;
}}}}
{paramname} = PyUnicode_READ_CHAR({argname}, 0);
Expand Down