Skip to content

Commit 25af12d

Browse files
committed
use Argument Clinic intead of PyArg_ParseTuple
1 parent 00582fe commit 25af12d

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

Modules/_typesmodule.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,31 @@
88
#include "pycore_unionobject.h" // _PyUnion_Type
99
#include "pycore_typeobject.h" // _PyObject_LookupSpecialMethod
1010
#include "pycore_stackref.h" // _PyStackRef
11+
#include "clinic/_typesmodule.c.h"
12+
13+
/*[clinic input]
14+
module _types
15+
[clinic start generated code]*/
16+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=530308b1011b659d]*/
17+
18+
/*[clinic input]
19+
_types.lookup_special_method
20+
21+
obj: 'O'
22+
attr: 'O'
23+
/
24+
25+
Lookup special method name `attr` on `obj`.
26+
27+
Lookup method `attr` on `obj` without looking in the instance dictionary.
28+
Returns `None` if the method is not found.
29+
[clinic start generated code]*/
1130

1231
static PyObject *
13-
_types_lookup_special_method_impl(PyObject *self, PyObject *args)
32+
_types_lookup_special_method_impl(PyObject *module, PyObject *obj,
33+
PyObject *attr)
34+
/*[clinic end generated code: output=890e22cc0b8e0d34 input=f26012b0c90b81cd]*/
1435
{
15-
PyObject *obj, *attr;
16-
if (!PyArg_ParseTuple(args, "OO", &obj, &attr)) {
17-
return NULL;
18-
}
1936
if (!PyUnicode_Check(attr)) {
2037
PyErr_Format(PyExc_TypeError,
2138
"attribute name must be string, not '%.200s'",
@@ -90,11 +107,9 @@ static struct PyModuleDef_Slot _typesmodule_slots[] = {
90107
};
91108

92109
static PyMethodDef _typesmodule_methods[] = {
93-
{"lookup_special_method", _types_lookup_special_method_impl, METH_VARARGS,
94-
"lookup_special_method(obj, attr, /)\n--\n\n"
95-
"Do a method lookup in the type without looking in the instance "
96-
"dictionary. Returns None if the method is not found."},
97-
{NULL, NULL, 0, NULL}};
110+
_TYPES_LOOKUP_SPECIAL_METHOD_METHODDEF
111+
{NULL, NULL, 0, NULL}
112+
};
98113

99114
static struct PyModuleDef typesmodule = {
100115
.m_base = PyModuleDef_HEAD_INIT,

0 commit comments

Comments
 (0)