Coverage Report

Created: 2026-10-31 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Objects/clinic/tupleobject.c.h
Line
Count
Source
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
#include "pycore_modsupport.h"    // _PyArg_CheckPositional()
6
7
PyDoc_STRVAR(tuple_index__doc__,
8
"index($self, value, start=0, stop=sys.maxsize, /)\n"
9
"--\n"
10
"\n"
11
"Return first index of value.\n"
12
"\n"
13
"Raises ValueError if the value is not present.");
14
15
#define TUPLE_INDEX_METHODDEF    \
16
    {"index", _PyCFunction_CAST(tuple_index), METH_FASTCALL, tuple_index__doc__},
17
18
static PyObject *
19
tuple_index_impl(PyTupleObject *self, PyObject *value, Py_ssize_t start,
20
                 Py_ssize_t stop);
21
22
static PyObject *
23
tuple_index(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
24
724
{
25
724
    PyObject *return_value = NULL;
26
724
    PyObject *value;
27
724
    Py_ssize_t start = 0;
28
724
    Py_ssize_t stop = PY_SSIZE_T_MAX;
29
30
724
    if (!_PyArg_CheckPositional("index", nargs, 1, 3)) {
31
0
        goto exit;
32
0
    }
33
724
    value = args[0];
34
724
    if (nargs < 2) {
35
724
        goto skip_optional;
36
724
    }
37
0
    if (!_PyEval_SliceIndexNotNone(args[1], &start)) {
38
0
        goto exit;
39
0
    }
40
0
    if (nargs < 3) {
41
0
        goto skip_optional;
42
0
    }
43
0
    if (!_PyEval_SliceIndexNotNone(args[2], &stop)) {
44
0
        goto exit;
45
0
    }
46
724
skip_optional:
47
724
    return_value = tuple_index_impl((PyTupleObject *)self, value, start, stop);
48
49
724
exit:
50
724
    return return_value;
51
724
}
52
53
PyDoc_STRVAR(tuple_count__doc__,
54
"count($self, value, /)\n"
55
"--\n"
56
"\n"
57
"Return number of occurrences of value.");
58
59
#define TUPLE_COUNT_METHODDEF    \
60
    {"count", (PyCFunction)tuple_count, METH_O, tuple_count__doc__},
61
62
static PyObject *
63
tuple_count_impl(PyTupleObject *self, PyObject *value);
64
65
static PyObject *
66
tuple_count(PyObject *self, PyObject *value)
67
0
{
68
0
    PyObject *return_value = NULL;
69
70
0
    return_value = tuple_count_impl((PyTupleObject *)self, value);
71
72
0
    return return_value;
73
0
}
74
75
PyDoc_STRVAR(tuple_new__doc__,
76
"tuple(iterable=(), /)\n"
77
"--\n"
78
"\n"
79
"Built-in immutable sequence.\n"
80
"\n"
81
"If no argument is given, the constructor returns an empty tuple.\n"
82
"If iterable is specified the tuple is initialized from iterable\'s items.\n"
83
"\n"
84
"If the argument is a tuple, the return value is the same object.");
85
86
static PyObject *
87
tuple_new_impl(PyTypeObject *type, PyObject *iterable);
88
89
static PyObject *
90
tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
91
584k
{
92
584k
    PyObject *return_value = NULL;
93
584k
    PyTypeObject *base_tp = &PyTuple_Type;
94
584k
    PyObject *iterable = NULL;
95
96
584k
    if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
97
584k
        !_PyArg_NoKeywords("tuple", kwargs)) {
98
0
        goto exit;
99
0
    }
100
584k
    if (!_PyArg_CheckPositional("tuple", PyTuple_GET_SIZE(args), 0, 1)) {
101
0
        goto exit;
102
0
    }
103
584k
    if (PyTuple_GET_SIZE(args) < 1) {
104
0
        goto skip_optional;
105
0
    }
106
584k
    iterable = PyTuple_GET_ITEM(args, 0);
107
584k
skip_optional:
108
584k
    return_value = tuple_new_impl(type, iterable);
109
110
584k
exit:
111
584k
    return return_value;
112
584k
}
113
114
static PyObject *
115
tuple_vectorcall(PyObject *type, PyObject *const *args,
116
    size_t nargsf, PyObject *kwnames)
117
212
{
118
212
    PyObject *return_value = NULL;
119
212
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
120
212
    PyObject *iterable = NULL;
121
122
212
    assert(_PyType_CAST(type)->tp_new == tuple_new);
123
    /* Make sure the type object is immutable: the generated
124
     * vectorcall doesn't deal e.g. with users reassigning __init__. */
125
212
    assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE));
126
212
    if (!_PyArg_NoKwnames("tuple", kwnames)) {
127
0
        goto exit;
128
0
    }
129
212
    if (!_PyArg_CheckPositional("tuple", nargs, 0, 1)) {
130
0
        goto exit;
131
0
    }
132
212
    if (nargs < 1) {
133
0
        goto skip_optional;
134
0
    }
135
212
    iterable = args[0];
136
212
skip_optional:
137
212
    return_value = tuple_new_impl(_PyType_CAST(type), iterable);
138
139
212
exit:
140
212
    return return_value;
141
212
}
142
143
PyDoc_STRVAR(tuple___getnewargs____doc__,
144
"__getnewargs__($self, /)\n"
145
"--\n"
146
"\n");
147
148
#define TUPLE___GETNEWARGS___METHODDEF    \
149
    {"__getnewargs__", (PyCFunction)tuple___getnewargs__, METH_NOARGS, tuple___getnewargs____doc__},
150
151
static PyObject *
152
tuple___getnewargs___impl(PyTupleObject *self);
153
154
static PyObject *
155
tuple___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored))
156
0
{
157
0
    return tuple___getnewargs___impl((PyTupleObject *)self);
158
0
}
159
/*[clinic end generated code: output=1bc2bfc233992933 input=a9049054013a1b77]*/