Coverage Report

Created: 2025-07-11 06:59

/src/Python-3.8.3/Objects/clinic/listobject.c.h
Line
Count
Source (jump to first uncovered line)
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 *
18
list_insert(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
19
0
{
20
0
    PyObject *return_value = NULL;
21
0
    Py_ssize_t index;
22
0
    PyObject *object;
23
24
0
    if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) {
25
0
        goto exit;
26
0
    }
27
0
    if (PyFloat_Check(args[0])) {
28
0
        PyErr_SetString(PyExc_TypeError,
29
0
                        "integer argument expected, got float" );
30
0
        goto exit;
31
0
    }
32
0
    {
33
0
        Py_ssize_t ival = -1;
34
0
        PyObject *iobj = PyNumber_Index(args[0]);
35
0
        if (iobj != NULL) {
36
0
            ival = PyLong_AsSsize_t(iobj);
37
0
            Py_DECREF(iobj);
38
0
        }
39
0
        if (ival == -1 && PyErr_Occurred()) {
40
0
            goto exit;
41
0
        }
42
0
        index = ival;
43
0
    }
44
0
    object = args[1];
45
0
    return_value = list_insert_impl(self, index, object);
46
47
0
exit:
48
0
    return return_value;
49
0
}
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 *
64
list_clear(PyListObject *self, PyObject *Py_UNUSED(ignored))
65
0
{
66
0
    return list_clear_impl(self);
67
0
}
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 *
82
list_copy(PyListObject *self, PyObject *Py_UNUSED(ignored))
83
0
{
84
0
    return list_copy_impl(self);
85
0
}
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 *
120
list_pop(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
121
0
{
122
0
    PyObject *return_value = NULL;
123
0
    Py_ssize_t index = -1;
124
125
0
    if (!_PyArg_CheckPositional("pop", nargs, 0, 1)) {
126
0
        goto exit;
127
0
    }
128
0
    if (nargs < 1) {
129
0
        goto skip_optional;
130
0
    }
131
0
    if (PyFloat_Check(args[0])) {
132
0
        PyErr_SetString(PyExc_TypeError,
133
0
                        "integer argument expected, got float" );
134
0
        goto exit;
135
0
    }
136
0
    {
137
0
        Py_ssize_t ival = -1;
138
0
        PyObject *iobj = PyNumber_Index(args[0]);
139
0
        if (iobj != NULL) {
140
0
            ival = PyLong_AsSsize_t(iobj);
141
0
            Py_DECREF(iobj);
142
0
        }
143
0
        if (ival == -1 && PyErr_Occurred()) {
144
0
            goto exit;
145
0
        }
146
0
        index = ival;
147
0
    }
148
0
skip_optional:
149
0
    return_value = list_pop_impl(self, index);
150
151
0
exit:
152
0
    return return_value;
153
0
}
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 *
176
list_sort(PyListObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
177
3
{
178
3
    PyObject *return_value = NULL;
179
3
    static const char * const _keywords[] = {"key", "reverse", NULL};
180
3
    static _PyArg_Parser _parser = {NULL, _keywords, "sort", 0};
181
3
    PyObject *argsbuf[2];
182
3
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
183
3
    PyObject *keyfunc = Py_None;
184
3
    int reverse = 0;
185
186
3
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
187
3
    if (!args) {
188
0
        goto exit;
189
0
    }
190
3
    if (!noptargs) {
191
0
        goto skip_optional_kwonly;
192
0
    }
193
3
    if (args[0]) {
194
2
        keyfunc = args[0];
195
2
        if (!--noptargs) {
196
0
            goto skip_optional_kwonly;
197
0
        }
198
2
    }
199
3
    if (PyFloat_Check(args[1])) {
200
0
        PyErr_SetString(PyExc_TypeError,
201
0
                        "integer argument expected, got float" );
202
0
        goto exit;
203
0
    }
204
3
    reverse = _PyLong_AsInt(args[1]);
205
3
    if (reverse == -1 && PyErr_Occurred()) {
206
0
        goto exit;
207
0
    }
208
3
skip_optional_kwonly:
209
3
    return_value = list_sort_impl(self, keyfunc, reverse);
210
211
3
exit:
212
3
    return return_value;
213
3
}
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 *
228
list_reverse(PyListObject *self, PyObject *Py_UNUSED(ignored))
229
0
{
230
0
    return list_reverse_impl(self);
231
0
}
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 *
249
list_index(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
250
0
{
251
0
    PyObject *return_value = NULL;
252
0
    PyObject *value;
253
0
    Py_ssize_t start = 0;
254
0
    Py_ssize_t stop = PY_SSIZE_T_MAX;
255
256
0
    if (!_PyArg_CheckPositional("index", nargs, 1, 3)) {
257
0
        goto exit;
258
0
    }
259
0
    value = args[0];
260
0
    if (nargs < 2) {
261
0
        goto skip_optional;
262
0
    }
263
0
    if (!_PyEval_SliceIndexNotNone(args[1], &start)) {
264
0
        goto exit;
265
0
    }
266
0
    if (nargs < 3) {
267
0
        goto skip_optional;
268
0
    }
269
0
    if (!_PyEval_SliceIndexNotNone(args[2], &stop)) {
270
0
        goto exit;
271
0
    }
272
0
skip_optional:
273
0
    return_value = list_index_impl(self, value, start, stop);
274
275
0
exit:
276
0
    return return_value;
277
0
}
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
312
list___init__(PyObject *self, PyObject *args, PyObject *kwargs)
313
35
{
314
35
    int return_value = -1;
315
35
    PyObject *iterable = NULL;
316
317
35
    if ((Py_TYPE(self) == &PyList_Type) &&
318
35
        !_PyArg_NoKeywords("list", kwargs)) {
319
0
        goto exit;
320
0
    }
321
35
    if (!_PyArg_CheckPositional("list", PyTuple_GET_SIZE(args), 0, 1)) {
322
0
        goto exit;
323
0
    }
324
35
    if (PyTuple_GET_SIZE(args) < 1) {
325
14
        goto skip_optional;
326
14
    }
327
21
    iterable = PyTuple_GET_ITEM(args, 0);
328
35
skip_optional:
329
35
    return_value = list___init___impl((PyListObject *)self, iterable);
330
331
35
exit:
332
35
    return return_value;
333
35
}
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 *
348
list___sizeof__(PyListObject *self, PyObject *Py_UNUSED(ignored))
349
0
{
350
0
    return list___sizeof___impl(self);
351
0
}
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 *
366
list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored))
367
16
{
368
16
    return list___reversed___impl(self);
369
16
}
370
/*[clinic end generated code: output=73718c0c33798c62 input=a9049054013a1b77]*/