• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 PyDoc_STRVAR(list_insert__doc__,
6 "insert($self, index, object, /)\n"
7 "--\n"
8 "\n"
9 "Insert object before index.");
10 
11 #define LIST_INSERT_METHODDEF    \
12     {"insert", (PyCFunction)(void(*)(void))list_insert, METH_FASTCALL, list_insert__doc__},
13 
14 static PyObject *
15 list_insert_impl(PyListObject *self, Py_ssize_t index, PyObject *object);
16 
17 static PyObject *
list_insert(PyListObject * self,PyObject * const * args,Py_ssize_t nargs)18 list_insert(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
19 {
20     PyObject *return_value = NULL;
21     Py_ssize_t index;
22     PyObject *object;
23 
24     if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) {
25         goto exit;
26     }
27     if (PyFloat_Check(args[0])) {
28         PyErr_SetString(PyExc_TypeError,
29                         "integer argument expected, got float" );
30         goto exit;
31     }
32     {
33         Py_ssize_t ival = -1;
34         PyObject *iobj = PyNumber_Index(args[0]);
35         if (iobj != NULL) {
36             ival = PyLong_AsSsize_t(iobj);
37             Py_DECREF(iobj);
38         }
39         if (ival == -1 && PyErr_Occurred()) {
40             goto exit;
41         }
42         index = ival;
43     }
44     object = args[1];
45     return_value = list_insert_impl(self, index, object);
46 
47 exit:
48     return return_value;
49 }
50 
51 PyDoc_STRVAR(list_clear__doc__,
52 "clear($self, /)\n"
53 "--\n"
54 "\n"
55 "Remove all items from list.");
56 
57 #define LIST_CLEAR_METHODDEF    \
58     {"clear", (PyCFunction)list_clear, METH_NOARGS, list_clear__doc__},
59 
60 static PyObject *
61 list_clear_impl(PyListObject *self);
62 
63 static PyObject *
list_clear(PyListObject * self,PyObject * Py_UNUSED (ignored))64 list_clear(PyListObject *self, PyObject *Py_UNUSED(ignored))
65 {
66     return list_clear_impl(self);
67 }
68 
69 PyDoc_STRVAR(list_copy__doc__,
70 "copy($self, /)\n"
71 "--\n"
72 "\n"
73 "Return a shallow copy of the list.");
74 
75 #define LIST_COPY_METHODDEF    \
76     {"copy", (PyCFunction)list_copy, METH_NOARGS, list_copy__doc__},
77 
78 static PyObject *
79 list_copy_impl(PyListObject *self);
80 
81 static PyObject *
list_copy(PyListObject * self,PyObject * Py_UNUSED (ignored))82 list_copy(PyListObject *self, PyObject *Py_UNUSED(ignored))
83 {
84     return list_copy_impl(self);
85 }
86 
87 PyDoc_STRVAR(list_append__doc__,
88 "append($self, object, /)\n"
89 "--\n"
90 "\n"
91 "Append object to the end of the list.");
92 
93 #define LIST_APPEND_METHODDEF    \
94     {"append", (PyCFunction)list_append, METH_O, list_append__doc__},
95 
96 PyDoc_STRVAR(list_extend__doc__,
97 "extend($self, iterable, /)\n"
98 "--\n"
99 "\n"
100 "Extend list by appending elements from the iterable.");
101 
102 #define LIST_EXTEND_METHODDEF    \
103     {"extend", (PyCFunction)list_extend, METH_O, list_extend__doc__},
104 
105 PyDoc_STRVAR(list_pop__doc__,
106 "pop($self, index=-1, /)\n"
107 "--\n"
108 "\n"
109 "Remove and return item at index (default last).\n"
110 "\n"
111 "Raises IndexError if list is empty or index is out of range.");
112 
113 #define LIST_POP_METHODDEF    \
114     {"pop", (PyCFunction)(void(*)(void))list_pop, METH_FASTCALL, list_pop__doc__},
115 
116 static PyObject *
117 list_pop_impl(PyListObject *self, Py_ssize_t index);
118 
119 static PyObject *
list_pop(PyListObject * self,PyObject * const * args,Py_ssize_t nargs)120 list_pop(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
121 {
122     PyObject *return_value = NULL;
123     Py_ssize_t index = -1;
124 
125     if (!_PyArg_CheckPositional("pop", nargs, 0, 1)) {
126         goto exit;
127     }
128     if (nargs < 1) {
129         goto skip_optional;
130     }
131     if (PyFloat_Check(args[0])) {
132         PyErr_SetString(PyExc_TypeError,
133                         "integer argument expected, got float" );
134         goto exit;
135     }
136     {
137         Py_ssize_t ival = -1;
138         PyObject *iobj = PyNumber_Index(args[0]);
139         if (iobj != NULL) {
140             ival = PyLong_AsSsize_t(iobj);
141             Py_DECREF(iobj);
142         }
143         if (ival == -1 && PyErr_Occurred()) {
144             goto exit;
145         }
146         index = ival;
147     }
148 skip_optional:
149     return_value = list_pop_impl(self, index);
150 
151 exit:
152     return return_value;
153 }
154 
155 PyDoc_STRVAR(list_sort__doc__,
156 "sort($self, /, *, key=None, reverse=False)\n"
157 "--\n"
158 "\n"
159 "Sort the list in ascending order and return None.\n"
160 "\n"
161 "The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n"
162 "order of two equal elements is maintained).\n"
163 "\n"
164 "If a key function is given, apply it once to each list item and sort them,\n"
165 "ascending or descending, according to their function values.\n"
166 "\n"
167 "The reverse flag can be set to sort in descending order.");
168 
169 #define LIST_SORT_METHODDEF    \
170     {"sort", (PyCFunction)(void(*)(void))list_sort, METH_FASTCALL|METH_KEYWORDS, list_sort__doc__},
171 
172 static PyObject *
173 list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse);
174 
175 static PyObject *
list_sort(PyListObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)176 list_sort(PyListObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
177 {
178     PyObject *return_value = NULL;
179     static const char * const _keywords[] = {"key", "reverse", NULL};
180     static _PyArg_Parser _parser = {NULL, _keywords, "sort", 0};
181     PyObject *argsbuf[2];
182     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
183     PyObject *keyfunc = Py_None;
184     int reverse = 0;
185 
186     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
187     if (!args) {
188         goto exit;
189     }
190     if (!noptargs) {
191         goto skip_optional_kwonly;
192     }
193     if (args[0]) {
194         keyfunc = args[0];
195         if (!--noptargs) {
196             goto skip_optional_kwonly;
197         }
198     }
199     if (PyFloat_Check(args[1])) {
200         PyErr_SetString(PyExc_TypeError,
201                         "integer argument expected, got float" );
202         goto exit;
203     }
204     reverse = _PyLong_AsInt(args[1]);
205     if (reverse == -1 && PyErr_Occurred()) {
206         goto exit;
207     }
208 skip_optional_kwonly:
209     return_value = list_sort_impl(self, keyfunc, reverse);
210 
211 exit:
212     return return_value;
213 }
214 
215 PyDoc_STRVAR(list_reverse__doc__,
216 "reverse($self, /)\n"
217 "--\n"
218 "\n"
219 "Reverse *IN PLACE*.");
220 
221 #define LIST_REVERSE_METHODDEF    \
222     {"reverse", (PyCFunction)list_reverse, METH_NOARGS, list_reverse__doc__},
223 
224 static PyObject *
225 list_reverse_impl(PyListObject *self);
226 
227 static PyObject *
list_reverse(PyListObject * self,PyObject * Py_UNUSED (ignored))228 list_reverse(PyListObject *self, PyObject *Py_UNUSED(ignored))
229 {
230     return list_reverse_impl(self);
231 }
232 
233 PyDoc_STRVAR(list_index__doc__,
234 "index($self, value, start=0, stop=sys.maxsize, /)\n"
235 "--\n"
236 "\n"
237 "Return first index of value.\n"
238 "\n"
239 "Raises ValueError if the value is not present.");
240 
241 #define LIST_INDEX_METHODDEF    \
242     {"index", (PyCFunction)(void(*)(void))list_index, METH_FASTCALL, list_index__doc__},
243 
244 static PyObject *
245 list_index_impl(PyListObject *self, PyObject *value, Py_ssize_t start,
246                 Py_ssize_t stop);
247 
248 static PyObject *
list_index(PyListObject * self,PyObject * const * args,Py_ssize_t nargs)249 list_index(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
250 {
251     PyObject *return_value = NULL;
252     PyObject *value;
253     Py_ssize_t start = 0;
254     Py_ssize_t stop = PY_SSIZE_T_MAX;
255 
256     if (!_PyArg_CheckPositional("index", nargs, 1, 3)) {
257         goto exit;
258     }
259     value = args[0];
260     if (nargs < 2) {
261         goto skip_optional;
262     }
263     if (!_PyEval_SliceIndexNotNone(args[1], &start)) {
264         goto exit;
265     }
266     if (nargs < 3) {
267         goto skip_optional;
268     }
269     if (!_PyEval_SliceIndexNotNone(args[2], &stop)) {
270         goto exit;
271     }
272 skip_optional:
273     return_value = list_index_impl(self, value, start, stop);
274 
275 exit:
276     return return_value;
277 }
278 
279 PyDoc_STRVAR(list_count__doc__,
280 "count($self, value, /)\n"
281 "--\n"
282 "\n"
283 "Return number of occurrences of value.");
284 
285 #define LIST_COUNT_METHODDEF    \
286     {"count", (PyCFunction)list_count, METH_O, list_count__doc__},
287 
288 PyDoc_STRVAR(list_remove__doc__,
289 "remove($self, value, /)\n"
290 "--\n"
291 "\n"
292 "Remove first occurrence of value.\n"
293 "\n"
294 "Raises ValueError if the value is not present.");
295 
296 #define LIST_REMOVE_METHODDEF    \
297     {"remove", (PyCFunction)list_remove, METH_O, list_remove__doc__},
298 
299 PyDoc_STRVAR(list___init____doc__,
300 "list(iterable=(), /)\n"
301 "--\n"
302 "\n"
303 "Built-in mutable sequence.\n"
304 "\n"
305 "If no argument is given, the constructor creates a new empty list.\n"
306 "The argument must be an iterable if specified.");
307 
308 static int
309 list___init___impl(PyListObject *self, PyObject *iterable);
310 
311 static int
list___init__(PyObject * self,PyObject * args,PyObject * kwargs)312 list___init__(PyObject *self, PyObject *args, PyObject *kwargs)
313 {
314     int return_value = -1;
315     PyObject *iterable = NULL;
316 
317     if (Py_IS_TYPE(self, &PyList_Type) &&
318         !_PyArg_NoKeywords("list", kwargs)) {
319         goto exit;
320     }
321     if (!_PyArg_CheckPositional("list", PyTuple_GET_SIZE(args), 0, 1)) {
322         goto exit;
323     }
324     if (PyTuple_GET_SIZE(args) < 1) {
325         goto skip_optional;
326     }
327     iterable = PyTuple_GET_ITEM(args, 0);
328 skip_optional:
329     return_value = list___init___impl((PyListObject *)self, iterable);
330 
331 exit:
332     return return_value;
333 }
334 
335 PyDoc_STRVAR(list___sizeof____doc__,
336 "__sizeof__($self, /)\n"
337 "--\n"
338 "\n"
339 "Return the size of the list in memory, in bytes.");
340 
341 #define LIST___SIZEOF___METHODDEF    \
342     {"__sizeof__", (PyCFunction)list___sizeof__, METH_NOARGS, list___sizeof____doc__},
343 
344 static PyObject *
345 list___sizeof___impl(PyListObject *self);
346 
347 static PyObject *
list___sizeof__(PyListObject * self,PyObject * Py_UNUSED (ignored))348 list___sizeof__(PyListObject *self, PyObject *Py_UNUSED(ignored))
349 {
350     return list___sizeof___impl(self);
351 }
352 
353 PyDoc_STRVAR(list___reversed____doc__,
354 "__reversed__($self, /)\n"
355 "--\n"
356 "\n"
357 "Return a reverse iterator over the list.");
358 
359 #define LIST___REVERSED___METHODDEF    \
360     {"__reversed__", (PyCFunction)list___reversed__, METH_NOARGS, list___reversed____doc__},
361 
362 static PyObject *
363 list___reversed___impl(PyListObject *self);
364 
365 static PyObject *
list___reversed__(PyListObject * self,PyObject * Py_UNUSED (ignored))366 list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored))
367 {
368     return list___reversed___impl(self);
369 }
370 /*[clinic end generated code: output=1ff61490c091d165 input=a9049054013a1b77]*/
371