Skip to content

Commit 235b594

Browse files
Better error message
1 parent af25677 commit 235b594

File tree

6 files changed

+54
-21
lines changed

6 files changed

+54
-21
lines changed

Lib/test/clinic.test.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,9 @@ test_int_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10281028
goto exit;
10291029
}
10301030
if (PyUnicode_GET_LENGTH(args[2]) != 1) {
1031-
PyErr_SetString(PyExc_ValueError, "a single unicode character expected");
1031+
PyErr_Format(PyExc_ValueError,
1032+
"test_int_converter(): argument 3 must be a single unicode character, not %T",
1033+
args[2]);
10321034
goto exit;
10331035
}
10341036
c = PyUnicode_READ_CHAR(args[2], 0);
@@ -1048,7 +1050,7 @@ test_int_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10481050

10491051
static PyObject *
10501052
test_int_converter_impl(PyObject *module, int a, int b, int c, myenum d)
1051-
/*[clinic end generated code: output=ec176dff0664c4a5 input=d20541fc1ca0553e]*/
1053+
/*[clinic end generated code: output=fcb777a9311da2f5 input=d20541fc1ca0553e]*/
10521054

10531055

10541056
/*[clinic input]

Modules/clinic/_testclinic.c.h

Lines changed: 4 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: 4 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: 31 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: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/clinic/libclinic/converters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,14 @@ def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> st
272272
goto exit;
273273
}}}}
274274
if (PyUnicode_GET_LENGTH({argname}) != 1) {{{{
275-
PyErr_SetString(PyExc_ValueError, "a single unicode character expected");
275+
PyErr_Format(PyExc_ValueError,
276+
"{{name}}(): {displayname} must be a single unicode character, not %T",
277+
{argname});
276278
goto exit;
277279
}}}}
278280
{paramname} = PyUnicode_READ_CHAR({argname}, 0);
279281
""",
282+
displayname=displayname,
280283
argname=argname,
281284
bad_argument=self.bad_argument(displayname, 'a unicode character', limited_capi=limited_capi),
282285
)

0 commit comments

Comments
 (0)