1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 PyDoc_STRVAR(tuple_index__doc__,
6 "index($self, value, start=0, stop=sys.maxsize, /)\n"
7 "--\n"
8 "\n"
9 "Return first index of value.\n"
10 "\n"
11 "Raises ValueError if the value is not present.");
12
13 #define TUPLE_INDEX_METHODDEF \
14 {"index", (PyCFunction)(void(*)(void))tuple_index, METH_FASTCALL, tuple_index__doc__},
15
16 static PyObject *
17 tuple_index_impl(PyTupleObject *self, PyObject *value, Py_ssize_t start,
18 Py_ssize_t stop);
19
20 static PyObject *
tuple_index(PyTupleObject * self,PyObject * const * args,Py_ssize_t nargs)21 tuple_index(PyTupleObject *self, PyObject *const *args, Py_ssize_t nargs)
22 {
23 PyObject *return_value = NULL;
24 PyObject *value;
25 Py_ssize_t start = 0;
26 Py_ssize_t stop = PY_SSIZE_T_MAX;
27
28 if (!_PyArg_CheckPositional("index", nargs, 1, 3)) {
29 goto exit;
30 }
31 value = args[0];
32 if (nargs < 2) {
33 goto skip_optional;
34 }
35 if (!_PyEval_SliceIndexNotNone(args[1], &start)) {
36 goto exit;
37 }
38 if (nargs < 3) {
39 goto skip_optional;
40 }
41 if (!_PyEval_SliceIndexNotNone(args[2], &stop)) {
42 goto exit;
43 }
44 skip_optional:
45 return_value = tuple_index_impl(self, value, start, stop);
46
47 exit:
48 return return_value;
49 }
50
51 PyDoc_STRVAR(tuple_count__doc__,
52 "count($self, value, /)\n"
53 "--\n"
54 "\n"
55 "Return number of occurrences of value.");
56
57 #define TUPLE_COUNT_METHODDEF \
58 {"count", (PyCFunction)tuple_count, METH_O, tuple_count__doc__},
59
60 PyDoc_STRVAR(tuple_new__doc__,
61 "tuple(iterable=(), /)\n"
62 "--\n"
63 "\n"
64 "Built-in immutable sequence.\n"
65 "\n"
66 "If no argument is given, the constructor returns an empty tuple.\n"
67 "If iterable is specified the tuple is initialized from iterable\'s items.\n"
68 "\n"
69 "If the argument is a tuple, the return value is the same object.");
70
71 static PyObject *
72 tuple_new_impl(PyTypeObject *type, PyObject *iterable);
73
74 static PyObject *
tuple_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)75 tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
76 {
77 PyObject *return_value = NULL;
78 PyObject *iterable = NULL;
79
80 if ((type == &PyTuple_Type) &&
81 !_PyArg_NoKeywords("tuple", kwargs)) {
82 goto exit;
83 }
84 if (!_PyArg_CheckPositional("tuple", PyTuple_GET_SIZE(args), 0, 1)) {
85 goto exit;
86 }
87 if (PyTuple_GET_SIZE(args) < 1) {
88 goto skip_optional;
89 }
90 iterable = PyTuple_GET_ITEM(args, 0);
91 skip_optional:
92 return_value = tuple_new_impl(type, iterable);
93
94 exit:
95 return return_value;
96 }
97
98 PyDoc_STRVAR(tuple___getnewargs____doc__,
99 "__getnewargs__($self, /)\n"
100 "--\n"
101 "\n");
102
103 #define TUPLE___GETNEWARGS___METHODDEF \
104 {"__getnewargs__", (PyCFunction)tuple___getnewargs__, METH_NOARGS, tuple___getnewargs____doc__},
105
106 static PyObject *
107 tuple___getnewargs___impl(PyTupleObject *self);
108
109 static PyObject *
tuple___getnewargs__(PyTupleObject * self,PyObject * Py_UNUSED (ignored))110 tuple___getnewargs__(PyTupleObject *self, PyObject *Py_UNUSED(ignored))
111 {
112 return tuple___getnewargs___impl(self);
113 }
114 /*[clinic end generated code: output=56fab9b7368aba49 input=a9049054013a1b77]*/
115