Skip to content

Commit 4a4e328

Browse files
pythongh-64631: Test exception messages in cloned Argument Clinic funcs
1 parent b0ce2db commit 4a4e328

File tree

3 files changed

+169
-1
lines changed

3 files changed

+169
-1
lines changed

Diff for: Lib/test/test_clinic.py

+7
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,13 @@ def test_gh_99240_double_free(self):
12841284
with self.assertRaisesRegex(TypeError, expected_error):
12851285
ac_tester.gh_99240_double_free('a', '\0b')
12861286

1287+
def test_cloned_func_exception_message(self):
1288+
incorrect_arg = -1 # f1() and f2() accept a single str
1289+
with self.assertRaisesRegex(TypeError, "clone_f1"):
1290+
ac_tester.clone_f1(incorrect_arg)
1291+
with self.assertRaisesRegex(TypeError, "clone_f2"):
1292+
ac_tester.clone_f2(incorrect_arg)
1293+
12871294

12881295
if __name__ == "__main__":
12891296
unittest.main()

Diff for: Modules/_testclinic.c

+29
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,33 @@ gh_99240_double_free_impl(PyObject *module, char *a, char *b)
11171117
}
11181118

11191119

1120+
/*[clinic input]
1121+
_testclinic.clone_f1 as clone_f1
1122+
path: str
1123+
1124+
[clinic start generated code]*/
1125+
1126+
static PyObject *
1127+
clone_f1_impl(PyObject *module, const char *path)
1128+
/*[clinic end generated code: output=8c30b5620ba86715 input=c956032414f389b4]*/
1129+
{
1130+
Py_RETURN_NONE;
1131+
}
1132+
1133+
1134+
/*[clinic input]
1135+
_testclinic.clone_f2 as clone_f2 = _testclinic.clone_f1
1136+
1137+
[clinic start generated code]*/
1138+
1139+
static PyObject *
1140+
clone_f2_impl(PyObject *module, const char *path)
1141+
/*[clinic end generated code: output=6aa1c39bec3f5d9b input=cf854c3ad41ddd85]*/
1142+
{
1143+
Py_RETURN_NONE;
1144+
}
1145+
1146+
11201147
static PyMethodDef tester_methods[] = {
11211148
TEST_EMPTY_FUNCTION_METHODDEF
11221149
OBJECTS_CONVERTER_METHODDEF
@@ -1168,6 +1195,8 @@ static PyMethodDef tester_methods[] = {
11681195
GH_32092_KW_PASS_METHODDEF
11691196
GH_99233_REFCOUNT_METHODDEF
11701197
GH_99240_DOUBLE_FREE_METHODDEF
1198+
CLONE_F1_METHODDEF
1199+
CLONE_F2_METHODDEF
11711200
{NULL, NULL}
11721201
};
11731202

Diff for: Modules/clinic/_testclinic.c.h

+133-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)