Skip to content

Commit fe02edd

Browse files
Address Serhiy's review
- try to make the error message even clearer - sync with PyArg_Parse
1 parent 9836259 commit fe02edd

File tree

7 files changed

+42
-23
lines changed

7 files changed

+42
-23
lines changed

Lib/test/clinic.test.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,8 @@ test_int_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10291029
}
10301030
if (PyUnicode_GET_LENGTH(args[2]) != 1) {
10311031
PyErr_SetString(PyExc_TypeError,
1032-
"test_int_converter(): argument 3 must be exactly one character long");
1032+
"test_int_converter(): argument 3 must be a string containing "
1033+
"exactly one unicode character");
10331034
goto exit;
10341035
}
10351036
c = PyUnicode_READ_CHAR(args[2], 0);
@@ -1049,7 +1050,7 @@ test_int_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10491050

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

10541055

10551056
/*[clinic input]

Modules/clinic/_testclinic.c.h

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/arraymodule.c.h

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/unicodedata.c.h

Lines changed: 21 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PC/clinic/msvcrtmodule.c.h

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/getargs.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,13 @@ static const char *
575575
converterr(const char *expected, PyObject *arg, char *msgbuf, size_t bufsize)
576576
{
577577
assert(expected != NULL);
578-
assert(arg != NULL);
579578
if (expected[0] == '(') {
580579
PyOS_snprintf(msgbuf, bufsize,
581580
"%.100s", expected);
582581
}
582+
else if (arg == NULL} {
583+
PyOS_snprintf(msgbuf, bufsize, "must be %.100s", expected);
584+
}
583585
else {
584586
PyOS_snprintf(msgbuf, bufsize,
585587
"must be %.50s, not %.50s", expected,
@@ -812,7 +814,8 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
812814
return converterr("a unicode character", arg, msgbuf, bufsize);
813815

814816
if (PyUnicode_GET_LENGTH(arg) != 1)
815-
return converterr("a unicode character", arg, msgbuf, bufsize);
817+
return converterr("a string containing exactly one unicode character",
818+
NULL, msgbuf, bufsize);
816819

817820
kind = PyUnicode_KIND(arg);
818821
data = PyUnicode_DATA(arg);

Tools/clinic/libclinic/converters.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> st
273273
}}}}
274274
if (PyUnicode_GET_LENGTH({argname}) != 1) {{{{
275275
PyErr_SetString(PyExc_TypeError,
276-
"{{name}}(): {displayname} must be exactly one character long");
276+
"{{name}}(): {displayname} must be a string containing "
277+
"exactly one unicode character");
277278
goto exit;
278279
}}}}
279280
{paramname} = PyUnicode_READ_CHAR({argname}, 0);

0 commit comments

Comments
 (0)