gh-107782: Use _testcapi to test non-representable signatures (GH-109325)

Builtin functions and methods that have non-representable signatures today
will have representable signatures yesterday, and they will become unusable
for testing this feature.

So we need to add special functions and methods to the _testcapi module
that always have non-representable signatures.
This commit is contained in:
Serhiy Storchaka 2023-09-14 09:12:17 +03:00 • committed by GitHub
parent a806e920c4
commit 1f885df2a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 82 additions and 2 deletions

View file

@ -100,6 +100,13 @@ static PyMethodDef test_methods[] = {
{"test_with_docstring",
test_with_docstring, METH_VARARGS,
PyDoc_STR("This is a pretty normal docstring.")},
{"func_with_unrepresentable_signature",
(PyCFunction)test_with_docstring, METH_VARARGS,
PyDoc_STR(
"func_with_unrepresentable_signature($module, /, a, b=<x>)\n"
"--\n\n"
"This docstring has a signature with unrepresentable default."
)},
{NULL},
};
@ -140,6 +147,40 @@ static PyTypeObject DocStringNoSignatureTest = {
.tp_new = PyType_GenericNew,
};
static PyMethodDef DocStringUnrepresentableSignatureTest_methods[] = {
{"meth",
(PyCFunction)test_with_docstring, METH_VARARGS,
PyDoc_STR(
"meth($self, /, a, b=<x>)\n"
"--\n\n"
"This docstring has a signature with unrepresentable default."
)},
{"classmeth",
(PyCFunction)test_with_docstring, METH_VARARGS|METH_CLASS,
PyDoc_STR(
"classmeth($type, /, a, b=<x>)\n"
"--\n\n"
"This docstring has a signature with unrepresentable default."
)},
{"staticmeth",
(PyCFunction)test_with_docstring, METH_VARARGS|METH_STATIC,
PyDoc_STR(
"staticmeth(a, b=<x>)\n"
"--\n\n"
"This docstring has a signature with unrepresentable default."
)},
{NULL},
};
static PyTypeObject DocStringUnrepresentableSignatureTest = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "_testcapi.DocStringUnrepresentableSignatureTest",
.tp_basicsize = sizeof(PyObject),
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_methods = DocStringUnrepresentableSignatureTest_methods,
.tp_new = PyType_GenericNew,
};
int
_PyTestCapi_Init_Docstring(PyObject *mod)
{
@ -149,5 +190,8 @@ _PyTestCapi_Init_Docstring(PyObject *mod)
if (PyModule_AddType(mod, &DocStringNoSignatureTest) < 0) {
return -1;
}
if (PyModule_AddType(mod, &DocStringUnrepresentableSignatureTest) < 0) {
return -1;
}
return 0;
}