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)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_ParseStack(args, nargs, "nO:insert",
25 &index, &object)) {
26 goto exit;
27 }
28 return_value = list_insert_impl(self, index, object);
29
30 exit:
31 return return_value;
32 }
33
34 PyDoc_STRVAR(list_clear__doc__,
35 "clear($self, /)\n"
36 "--\n"
37 "\n"
38 "Remove all items from list.");
39
40 #define LIST_CLEAR_METHODDEF \
41 {"clear", (PyCFunction)list_clear, METH_NOARGS, list_clear__doc__},
42
43 static PyObject *
44 list_clear_impl(PyListObject *self);
45
46 static PyObject *
list_clear(PyListObject * self,PyObject * Py_UNUSED (ignored))47 list_clear(PyListObject *self, PyObject *Py_UNUSED(ignored))
48 {
49 return list_clear_impl(self);
50 }
51
52 PyDoc_STRVAR(list_copy__doc__,
53 "copy($self, /)\n"
54 "--\n"
55 "\n"
56 "Return a shallow copy of the list.");
57
58 #define LIST_COPY_METHODDEF \
59 {"copy", (PyCFunction)list_copy, METH_NOARGS, list_copy__doc__},
60
61 static PyObject *
62 list_copy_impl(PyListObject *self);
63
64 static PyObject *
list_copy(PyListObject * self,PyObject * Py_UNUSED (ignored))65 list_copy(PyListObject *self, PyObject *Py_UNUSED(ignored))
66 {
67 return list_copy_impl(self);
68 }
69
70 PyDoc_STRVAR(list_append__doc__,
71 "append($self, object, /)\n"
72 "--\n"
73 "\n"
74 "Append object to the end of the list.");
75
76 #define LIST_APPEND_METHODDEF \
77 {"append", (PyCFunction)list_append, METH_O, list_append__doc__},
78
79 PyDoc_STRVAR(list_extend__doc__,
80 "extend($self, iterable, /)\n"
81 "--\n"
82 "\n"
83 "Extend list by appending elements from the iterable.");
84
85 #define LIST_EXTEND_METHODDEF \
86 {"extend", (PyCFunction)list_extend, METH_O, list_extend__doc__},
87
88 PyDoc_STRVAR(list_pop__doc__,
89 "pop($self, index=-1, /)\n"
90 "--\n"
91 "\n"
92 "Remove and return item at index (default last).\n"
93 "\n"
94 "Raises IndexError if list is empty or index is out of range.");
95
96 #define LIST_POP_METHODDEF \
97 {"pop", (PyCFunction)list_pop, METH_FASTCALL, list_pop__doc__},
98
99 static PyObject *
100 list_pop_impl(PyListObject *self, Py_ssize_t index);
101
102 static PyObject *
list_pop(PyListObject * self,PyObject * const * args,Py_ssize_t nargs)103 list_pop(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
104 {
105 PyObject *return_value = NULL;
106 Py_ssize_t index = -1;
107
108 if (!_PyArg_ParseStack(args, nargs, "|n:pop",
109 &index)) {
110 goto exit;
111 }
112 return_value = list_pop_impl(self, index);
113
114 exit:
115 return return_value;
116 }
117
118 PyDoc_STRVAR(list_sort__doc__,
119 "sort($self, /, *, key=None, reverse=False)\n"
120 "--\n"
121 "\n"
122 "Stable sort *IN PLACE*.");
123
124 #define LIST_SORT_METHODDEF \
125 {"sort", (PyCFunction)list_sort, METH_FASTCALL|METH_KEYWORDS, list_sort__doc__},
126
127 static PyObject *
128 list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse);
129
130 static PyObject *
list_sort(PyListObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)131 list_sort(PyListObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
132 {
133 PyObject *return_value = NULL;
134 static const char * const _keywords[] = {"key", "reverse", NULL};
135 static _PyArg_Parser _parser = {"|$Oi:sort", _keywords, 0};
136 PyObject *keyfunc = Py_None;
137 int reverse = 0;
138
139 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
140 &keyfunc, &reverse)) {
141 goto exit;
142 }
143 return_value = list_sort_impl(self, keyfunc, reverse);
144
145 exit:
146 return return_value;
147 }
148
149 PyDoc_STRVAR(list_reverse__doc__,
150 "reverse($self, /)\n"
151 "--\n"
152 "\n"
153 "Reverse *IN PLACE*.");
154
155 #define LIST_REVERSE_METHODDEF \
156 {"reverse", (PyCFunction)list_reverse, METH_NOARGS, list_reverse__doc__},
157
158 static PyObject *
159 list_reverse_impl(PyListObject *self);
160
161 static PyObject *
list_reverse(PyListObject * self,PyObject * Py_UNUSED (ignored))162 list_reverse(PyListObject *self, PyObject *Py_UNUSED(ignored))
163 {
164 return list_reverse_impl(self);
165 }
166
167 PyDoc_STRVAR(list_index__doc__,
168 "index($self, value, start=0, stop=sys.maxsize, /)\n"
169 "--\n"
170 "\n"
171 "Return first index of value.\n"
172 "\n"
173 "Raises ValueError if the value is not present.");
174
175 #define LIST_INDEX_METHODDEF \
176 {"index", (PyCFunction)list_index, METH_FASTCALL, list_index__doc__},
177
178 static PyObject *
179 list_index_impl(PyListObject *self, PyObject *value, Py_ssize_t start,
180 Py_ssize_t stop);
181
182 static PyObject *
list_index(PyListObject * self,PyObject * const * args,Py_ssize_t nargs)183 list_index(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
184 {
185 PyObject *return_value = NULL;
186 PyObject *value;
187 Py_ssize_t start = 0;
188 Py_ssize_t stop = PY_SSIZE_T_MAX;
189
190 if (!_PyArg_ParseStack(args, nargs, "O|O&O&:index",
191 &value, _PyEval_SliceIndexNotNone, &start, _PyEval_SliceIndexNotNone, &stop)) {
192 goto exit;
193 }
194 return_value = list_index_impl(self, value, start, stop);
195
196 exit:
197 return return_value;
198 }
199
200 PyDoc_STRVAR(list_count__doc__,
201 "count($self, value, /)\n"
202 "--\n"
203 "\n"
204 "Return number of occurrences of value.");
205
206 #define LIST_COUNT_METHODDEF \
207 {"count", (PyCFunction)list_count, METH_O, list_count__doc__},
208
209 PyDoc_STRVAR(list_remove__doc__,
210 "remove($self, value, /)\n"
211 "--\n"
212 "\n"
213 "Remove first occurrence of value.\n"
214 "\n"
215 "Raises ValueError if the value is not present.");
216
217 #define LIST_REMOVE_METHODDEF \
218 {"remove", (PyCFunction)list_remove, METH_O, list_remove__doc__},
219
220 PyDoc_STRVAR(list___init____doc__,
221 "list(iterable=(), /)\n"
222 "--\n"
223 "\n"
224 "Built-in mutable sequence.\n"
225 "\n"
226 "If no argument is given, the constructor creates a new empty list.\n"
227 "The argument must be an iterable if specified.");
228
229 static int
230 list___init___impl(PyListObject *self, PyObject *iterable);
231
232 static int
list___init__(PyObject * self,PyObject * args,PyObject * kwargs)233 list___init__(PyObject *self, PyObject *args, PyObject *kwargs)
234 {
235 int return_value = -1;
236 PyObject *iterable = NULL;
237
238 if ((Py_TYPE(self) == &PyList_Type) &&
239 !_PyArg_NoKeywords("list", kwargs)) {
240 goto exit;
241 }
242 if (!PyArg_UnpackTuple(args, "list",
243 0, 1,
244 &iterable)) {
245 goto exit;
246 }
247 return_value = list___init___impl((PyListObject *)self, iterable);
248
249 exit:
250 return return_value;
251 }
252
253 PyDoc_STRVAR(list___sizeof____doc__,
254 "__sizeof__($self, /)\n"
255 "--\n"
256 "\n"
257 "Return the size of the list in memory, in bytes.");
258
259 #define LIST___SIZEOF___METHODDEF \
260 {"__sizeof__", (PyCFunction)list___sizeof__, METH_NOARGS, list___sizeof____doc__},
261
262 static PyObject *
263 list___sizeof___impl(PyListObject *self);
264
265 static PyObject *
list___sizeof__(PyListObject * self,PyObject * Py_UNUSED (ignored))266 list___sizeof__(PyListObject *self, PyObject *Py_UNUSED(ignored))
267 {
268 return list___sizeof___impl(self);
269 }
270
271 PyDoc_STRVAR(list___reversed____doc__,
272 "__reversed__($self, /)\n"
273 "--\n"
274 "\n"
275 "Return a reverse iterator over the list.");
276
277 #define LIST___REVERSED___METHODDEF \
278 {"__reversed__", (PyCFunction)list___reversed__, METH_NOARGS, list___reversed____doc__},
279
280 static PyObject *
281 list___reversed___impl(PyListObject *self);
282
283 static PyObject *
list___reversed__(PyListObject * self,PyObject * Py_UNUSED (ignored))284 list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored))
285 {
286 return list___reversed___impl(self);
287 }
288 /*[clinic end generated code: output=d8cb29e6e6d79844 input=a9049054013a1b77]*/
289