Skip to content

Commit 5c643a0

Browse files
bpo-20185: Convert typeobject.c to Argument Clinic. (#544)
Based on patch by Vajrasky Kok.
1 parent bdf6b91 commit 5c643a0

File tree

2 files changed

+391
-76
lines changed

2 files changed

+391
-76
lines changed

Objects/clinic/typeobject.c.h

Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
/*[clinic input]
2+
preserve
3+
[clinic start generated code]*/
4+
5+
PyDoc_STRVAR(type___instancecheck____doc__,
6+
"__instancecheck__($self, instance, /)\n"
7+
"--\n"
8+
"\n"
9+
"Check if an object is an instance.");
10+
11+
#define TYPE___INSTANCECHECK___METHODDEF \
12+
{"__instancecheck__", (PyCFunction)type___instancecheck__, METH_O, type___instancecheck____doc__},
13+
14+
static int
15+
type___instancecheck___impl(PyTypeObject *self, PyObject *instance);
16+
17+
static PyObject *
18+
type___instancecheck__(PyTypeObject *self, PyObject *instance)
19+
{
20+
PyObject *return_value = NULL;
21+
int _return_value;
22+
23+
_return_value = type___instancecheck___impl(self, instance);
24+
if ((_return_value == -1) && PyErr_Occurred()) {
25+
goto exit;
26+
}
27+
return_value = PyBool_FromLong((long)_return_value);
28+
29+
exit:
30+
return return_value;
31+
}
32+
33+
PyDoc_STRVAR(type___subclasscheck____doc__,
34+
"__subclasscheck__($self, subclass, /)\n"
35+
"--\n"
36+
"\n"
37+
"Check if a class is a subclass.");
38+
39+
#define TYPE___SUBCLASSCHECK___METHODDEF \
40+
{"__subclasscheck__", (PyCFunction)type___subclasscheck__, METH_O, type___subclasscheck____doc__},
41+
42+
static int
43+
type___subclasscheck___impl(PyTypeObject *self, PyObject *subclass);
44+
45+
static PyObject *
46+
type___subclasscheck__(PyTypeObject *self, PyObject *subclass)
47+
{
48+
PyObject *return_value = NULL;
49+
int _return_value;
50+
51+
_return_value = type___subclasscheck___impl(self, subclass);
52+
if ((_return_value == -1) && PyErr_Occurred()) {
53+
goto exit;
54+
}
55+
return_value = PyBool_FromLong((long)_return_value);
56+
57+
exit:
58+
return return_value;
59+
}
60+
61+
PyDoc_STRVAR(type_mro__doc__,
62+
"mro($self, /)\n"
63+
"--\n"
64+
"\n"
65+
"Return a type\'s method resolution order.");
66+
67+
#define TYPE_MRO_METHODDEF \
68+
{"mro", (PyCFunction)type_mro, METH_NOARGS, type_mro__doc__},
69+
70+
static PyObject *
71+
type_mro_impl(PyTypeObject *self);
72+
73+
static PyObject *
74+
type_mro(PyTypeObject *self, PyObject *Py_UNUSED(ignored))
75+
{
76+
return type_mro_impl(self);
77+
}
78+
79+
PyDoc_STRVAR(type___subclasses____doc__,
80+
"__subclasses__($self, /)\n"
81+
"--\n"
82+
"\n"
83+
"Return a list of immediate subclasses.");
84+
85+
#define TYPE___SUBCLASSES___METHODDEF \
86+
{"__subclasses__", (PyCFunction)type___subclasses__, METH_NOARGS, type___subclasses____doc__},
87+
88+
static PyObject *
89+
type___subclasses___impl(PyTypeObject *self);
90+
91+
static PyObject *
92+
type___subclasses__(PyTypeObject *self, PyObject *Py_UNUSED(ignored))
93+
{
94+
return type___subclasses___impl(self);
95+
}
96+
97+
PyDoc_STRVAR(type___dir____doc__,
98+
"__dir__($self, /)\n"
99+
"--\n"
100+
"\n"
101+
"Specialized __dir__ implementation for types.");
102+
103+
#define TYPE___DIR___METHODDEF \
104+
{"__dir__", (PyCFunction)type___dir__, METH_NOARGS, type___dir____doc__},
105+
106+
static PyObject *
107+
type___dir___impl(PyTypeObject *self);
108+
109+
static PyObject *
110+
type___dir__(PyTypeObject *self, PyObject *Py_UNUSED(ignored))
111+
{
112+
return type___dir___impl(self);
113+
}
114+
115+
PyDoc_STRVAR(type___sizeof____doc__,
116+
"__sizeof__($self, /)\n"
117+
"--\n"
118+
"\n"
119+
"Return memory consumption of the type object.");
120+
121+
#define TYPE___SIZEOF___METHODDEF \
122+
{"__sizeof__", (PyCFunction)type___sizeof__, METH_NOARGS, type___sizeof____doc__},
123+
124+
static PyObject *
125+
type___sizeof___impl(PyTypeObject *self);
126+
127+
static PyObject *
128+
type___sizeof__(PyTypeObject *self, PyObject *Py_UNUSED(ignored))
129+
{
130+
return type___sizeof___impl(self);
131+
}
132+
133+
PyDoc_STRVAR(object___reduce____doc__,
134+
"__reduce__($self, protocol=0, /)\n"
135+
"--\n"
136+
"\n"
137+
"Helper for pickle.");
138+
139+
#define OBJECT___REDUCE___METHODDEF \
140+
{"__reduce__", (PyCFunction)object___reduce__, METH_FASTCALL, object___reduce____doc__},
141+
142+
static PyObject *
143+
object___reduce___impl(PyObject *self, int protocol);
144+
145+
static PyObject *
146+
object___reduce__(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
147+
{
148+
PyObject *return_value = NULL;
149+
int protocol = 0;
150+
151+
if (!_PyArg_ParseStack(args, nargs, "|i:__reduce__",
152+
&protocol)) {
153+
goto exit;
154+
}
155+
156+
if (!_PyArg_NoStackKeywords("__reduce__", kwnames)) {
157+
goto exit;
158+
}
159+
return_value = object___reduce___impl(self, protocol);
160+
161+
exit:
162+
return return_value;
163+
}
164+
165+
PyDoc_STRVAR(object___reduce_ex____doc__,
166+
"__reduce_ex__($self, protocol=0, /)\n"
167+
"--\n"
168+
"\n"
169+
"Helper for pickle.");
170+
171+
#define OBJECT___REDUCE_EX___METHODDEF \
172+
{"__reduce_ex__", (PyCFunction)object___reduce_ex__, METH_FASTCALL, object___reduce_ex____doc__},
173+
174+
static PyObject *
175+
object___reduce_ex___impl(PyObject *self, int protocol);
176+
177+
static PyObject *
178+
object___reduce_ex__(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
179+
{
180+
PyObject *return_value = NULL;
181+
int protocol = 0;
182+
183+
if (!_PyArg_ParseStack(args, nargs, "|i:__reduce_ex__",
184+
&protocol)) {
185+
goto exit;
186+
}
187+
188+
if (!_PyArg_NoStackKeywords("__reduce_ex__", kwnames)) {
189+
goto exit;
190+
}
191+
return_value = object___reduce_ex___impl(self, protocol);
192+
193+
exit:
194+
return return_value;
195+
}
196+
197+
PyDoc_STRVAR(object___format____doc__,
198+
"__format__($self, format_spec, /)\n"
199+
"--\n"
200+
"\n"
201+
"Default object formatter.");
202+
203+
#define OBJECT___FORMAT___METHODDEF \
204+
{"__format__", (PyCFunction)object___format__, METH_O, object___format____doc__},
205+
206+
static PyObject *
207+
object___format___impl(PyObject *self, PyObject *format_spec);
208+
209+
static PyObject *
210+
object___format__(PyObject *self, PyObject *arg)
211+
{
212+
PyObject *return_value = NULL;
213+
PyObject *format_spec;
214+
215+
if (!PyArg_Parse(arg, "U:__format__", &format_spec)) {
216+
goto exit;
217+
}
218+
return_value = object___format___impl(self, format_spec);
219+
220+
exit:
221+
return return_value;
222+
}
223+
224+
PyDoc_STRVAR(object___sizeof____doc__,
225+
"__sizeof__($self, /)\n"
226+
"--\n"
227+
"\n"
228+
"Size of object in memory, in bytes.");
229+
230+
#define OBJECT___SIZEOF___METHODDEF \
231+
{"__sizeof__", (PyCFunction)object___sizeof__, METH_NOARGS, object___sizeof____doc__},
232+
233+
static PyObject *
234+
object___sizeof___impl(PyObject *self);
235+
236+
static PyObject *
237+
object___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))
238+
{
239+
return object___sizeof___impl(self);
240+
}
241+
242+
PyDoc_STRVAR(object___dir____doc__,
243+
"__dir__($self, /)\n"
244+
"--\n"
245+
"\n"
246+
"Default dir() implementation.");
247+
248+
#define OBJECT___DIR___METHODDEF \
249+
{"__dir__", (PyCFunction)object___dir__, METH_NOARGS, object___dir____doc__},
250+
251+
static PyObject *
252+
object___dir___impl(PyObject *self);
253+
254+
static PyObject *
255+
object___dir__(PyObject *self, PyObject *Py_UNUSED(ignored))
256+
{
257+
return object___dir___impl(self);
258+
}
259+
/*[clinic end generated code: output=ce354e436e2360a0 input=a9049054013a1b77]*/

0 commit comments

Comments
 (0)