summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-08-11 15:08:38 (GMT)
committerGitHub <noreply@github.com>2023-08-11 15:08:38 (GMT)
commit3901c991e169da6fba8c0033a86a6f2e6146bb7f (patch)
tree204793d1f5428775539104f57fd289d8589435e8 /Modules
parent23a6db98f21cba3af69a921f01613bd5f602bf6d (diff)
downloadcpython-3901c991e169da6fba8c0033a86a6f2e6146bb7f.zip
cpython-3901c991e169da6fba8c0033a86a6f2e6146bb7f.tar.gz
cpython-3901c991e169da6fba8c0033a86a6f2e6146bb7f.tar.bz2
gh-84805: Autogenerate signature for METH_NOARGS and METH_O extension functions (GH-107794)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapi/docstring.c64
1 files changed, 55 insertions, 9 deletions
diff --git a/Modules/_testcapi/docstring.c b/Modules/_testcapi/docstring.c
index a997c54..b680171 100644
--- a/Modules/_testcapi/docstring.c
+++ b/Modules/_testcapi/docstring.c
@@ -66,42 +66,88 @@ test_with_docstring(PyObject *self, PyObject *Py_UNUSED(ignored))
static PyMethodDef test_methods[] = {
{"docstring_empty",
- (PyCFunction)test_with_docstring, METH_NOARGS,
+ (PyCFunction)test_with_docstring, METH_VARARGS,
docstring_empty},
{"docstring_no_signature",
+ (PyCFunction)test_with_docstring, METH_VARARGS,
+ docstring_no_signature},
+ {"docstring_no_signature_noargs",
(PyCFunction)test_with_docstring, METH_NOARGS,
docstring_no_signature},
+ {"docstring_no_signature_o",
+ (PyCFunction)test_with_docstring, METH_O,
+ docstring_no_signature},
{"docstring_with_invalid_signature",
- (PyCFunction)test_with_docstring, METH_NOARGS,
+ (PyCFunction)test_with_docstring, METH_VARARGS,
docstring_with_invalid_signature},
{"docstring_with_invalid_signature2",
- (PyCFunction)test_with_docstring, METH_NOARGS,
+ (PyCFunction)test_with_docstring, METH_VARARGS,
docstring_with_invalid_signature2},
{"docstring_with_signature",
- (PyCFunction)test_with_docstring, METH_NOARGS,
+ (PyCFunction)test_with_docstring, METH_VARARGS,
docstring_with_signature},
{"docstring_with_signature_and_extra_newlines",
- (PyCFunction)test_with_docstring, METH_NOARGS,
+ (PyCFunction)test_with_docstring, METH_VARARGS,
docstring_with_signature_and_extra_newlines},
{"docstring_with_signature_but_no_doc",
- (PyCFunction)test_with_docstring, METH_NOARGS,
+ (PyCFunction)test_with_docstring, METH_VARARGS,
docstring_with_signature_but_no_doc},
{"docstring_with_signature_with_defaults",
- (PyCFunction)test_with_docstring, METH_NOARGS,
+ (PyCFunction)test_with_docstring, METH_VARARGS,
docstring_with_signature_with_defaults},
{"no_docstring",
- (PyCFunction)test_with_docstring, METH_NOARGS},
+ (PyCFunction)test_with_docstring, METH_VARARGS},
{"test_with_docstring",
- test_with_docstring, METH_NOARGS,
+ test_with_docstring, METH_VARARGS,
PyDoc_STR("This is a pretty normal docstring.")},
{NULL},
};
+static PyMethodDef DocStringNoSignatureTest_methods[] = {
+ {"meth_noargs",
+ (PyCFunction)test_with_docstring, METH_NOARGS,
+ docstring_no_signature},
+ {"meth_o",
+ (PyCFunction)test_with_docstring, METH_O,
+ docstring_no_signature},
+ {"meth_noargs_class",
+ (PyCFunction)test_with_docstring, METH_NOARGS|METH_CLASS,
+ docstring_no_signature},
+ {"meth_o_class",
+ (PyCFunction)test_with_docstring, METH_O|METH_CLASS,
+ docstring_no_signature},
+ {"meth_noargs_static",
+ (PyCFunction)test_with_docstring, METH_NOARGS|METH_STATIC,
+ docstring_no_signature},
+ {"meth_o_static",
+ (PyCFunction)test_with_docstring, METH_O|METH_STATIC,
+ docstring_no_signature},
+ {"meth_noargs_coexist",
+ (PyCFunction)test_with_docstring, METH_NOARGS|METH_COEXIST,
+ docstring_no_signature},
+ {"meth_o_coexist",
+ (PyCFunction)test_with_docstring, METH_O|METH_COEXIST,
+ docstring_no_signature},
+ {NULL},
+};
+
+static PyTypeObject DocStringNoSignatureTest = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ .tp_name = "_testcapi.DocStringNoSignatureTest",
+ .tp_basicsize = sizeof(PyObject),
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+ .tp_methods = DocStringNoSignatureTest_methods,
+ .tp_new = PyType_GenericNew,
+};
+
int
_PyTestCapi_Init_Docstring(PyObject *mod)
{
if (PyModule_AddFunctions(mod, test_methods) < 0) {
return -1;
}
+ if (PyModule_AddType(mod, &DocStringNoSignatureTest) < 0) {
+ return -1;
+ }
return 0;
}