diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-08-11 15:08:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-11 15:08:38 (GMT) |
commit | 3901c991e169da6fba8c0033a86a6f2e6146bb7f (patch) | |
tree | 204793d1f5428775539104f57fd289d8589435e8 /Objects/typeobject.c | |
parent | 23a6db98f21cba3af69a921f01613bd5f602bf6d (diff) | |
download | cpython-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 'Objects/typeobject.c')
-rw-r--r-- | Objects/typeobject.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index aca14e7..030e8bf 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -586,8 +586,29 @@ _PyType_GetDocFromInternalDoc(const char *name, const char *internal_doc) return PyUnicode_FromString(doc); } +static const char * +signature_from_flags(int flags) +{ + switch (flags & ~METH_COEXIST) { + case METH_NOARGS: + return "($self, /)"; + case METH_NOARGS|METH_CLASS: + return "($type, /)"; + case METH_NOARGS|METH_STATIC: + return "()"; + case METH_O: + return "($self, object, /)"; + case METH_O|METH_CLASS: + return "($type, object, /)"; + case METH_O|METH_STATIC: + return "(object, /)"; + default: + return NULL; + } +} + PyObject * -_PyType_GetTextSignatureFromInternalDoc(const char *name, const char *internal_doc) +_PyType_GetTextSignatureFromInternalDoc(const char *name, const char *internal_doc, int flags) { const char *start = find_signature(name, internal_doc); const char *end; @@ -597,6 +618,10 @@ _PyType_GetTextSignatureFromInternalDoc(const char *name, const char *internal_d else end = NULL; if (!end) { + start = signature_from_flags(flags); + if (start) { + return PyUnicode_FromString(start); + } Py_RETURN_NONE; } @@ -1429,7 +1454,7 @@ type_get_doc(PyTypeObject *type, void *context) static PyObject * type_get_text_signature(PyTypeObject *type, void *context) { - return _PyType_GetTextSignatureFromInternalDoc(type->tp_name, type->tp_doc); + return _PyType_GetTextSignatureFromInternalDoc(type->tp_name, type->tp_doc, 0); } static int |