Coverage Report

Created: 2026-10-15 06:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython3/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
0
{
25
0
    PyObject *return_value = NULL;
26
0
    PyObject *value;
27
0
    Py_ssize_t start = 0;
28
0
    Py_ssize_t stop = PY_SSIZE_T_MAX;
29
30
0
    if (!_PyArg_CheckPositional("index", nargs, 1, 3)) {
31
0
        goto exit;
32
0
    }
33
0
    value = args[0];
34
0
    if (nargs < 2) {
35
0
        goto skip_optional;
36
0
    }
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
0
skip_optional:
47
0
    return_value = tuple_index_impl((PyTupleObject *)self, value, start, stop);
48
49
0
exit:
50
0
    return return_value;
51
0
}
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
355
{
92
355
    PyObject *return_value = NULL;
93
355
    PyTypeObject *base_tp = &PyTuple_Type;
94
355
    PyObject *iterable = NULL;
95
96
355
    if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
97
355
        !_PyArg_NoKeywords("tuple", kwargs)) {
98
0
        goto exit;
99
0
    }
100
355
    if (!_PyArg_CheckPositional("tuple", PyTuple_GET_SIZE(args), 0, 1)) {
101
0
        goto exit;
102
0
    }
103
355
    if (PyTuple_GET_SIZE(args) < 1) {
104
0
        goto skip_optional;
105
0
    }
106
355
    iterable = PyTuple_GET_ITEM(args, 0);
107
355
skip_optional:
108
355
    return_value = tuple_new_impl(type, iterable);
109
110
355
exit:
111
355
    return return_value;
112
355
}
113
114
static PyObject *
115
tuple_vectorcall(PyObject *type, PyObject *const *args,
116
    size_t nargsf, PyObject *kwnames)
117
37
{
118
37
    PyObject *return_value = NULL;
119
37
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
120
37
    PyObject *iterable = NULL;
121
122
37
    assert(Py_Is(_PyType_CAST(type), &PyTuple_Type));
123
    /* Make sure the type object is immutable: the generated
124
     * vectorcall doesn't deal e.g. with users reassigning __init__. */
125
37
    assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE));
126
37
    if (!_PyArg_NoKwnames("tuple", kwnames)) {
127
0
        goto exit;
128
0
    }
129
37
    if (!_PyArg_CheckPositional("tuple", nargs, 0, 1)) {
130
0
        goto exit;
131
0
    }
132
37
    if (nargs < 1) {
133
0
        goto skip_optional;
134
0
    }
135
37
    iterable = args[0];
136
37
skip_optional:
137
37
    return_value = tuple_new_impl(_PyType_CAST(type), iterable);
138
139
37
exit:
140
37
    return return_value;
141
37
}
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=69cab12f1ecb03e9 input=a9049054013a1b77]*/