Line data Source code
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_CAST(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 *
21 1720 : tuple_index(PyTupleObject *self, PyObject *const *args, Py_ssize_t nargs)
22 : {
23 1720 : PyObject *return_value = NULL;
24 : PyObject *value;
25 1720 : Py_ssize_t start = 0;
26 1720 : Py_ssize_t stop = PY_SSIZE_T_MAX;
27 :
28 1720 : if (!_PyArg_CheckPositional("index", nargs, 1, 3)) {
29 1 : goto exit;
30 : }
31 1719 : value = args[0];
32 1719 : if (nargs < 2) {
33 1704 : goto skip_optional;
34 : }
35 15 : if (!_PyEval_SliceIndexNotNone(args[1], &start)) {
36 0 : goto exit;
37 : }
38 15 : if (nargs < 3) {
39 8 : goto skip_optional;
40 : }
41 7 : if (!_PyEval_SliceIndexNotNone(args[2], &stop)) {
42 0 : goto exit;
43 : }
44 7 : skip_optional:
45 1719 : return_value = tuple_index_impl(self, value, start, stop);
46 :
47 1720 : exit:
48 1720 : 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 *
75 7908050 : tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
76 : {
77 7908050 : PyObject *return_value = NULL;
78 7908050 : PyObject *iterable = NULL;
79 :
80 7908050 : if ((type == &PyTuple_Type ||
81 7908050 : type->tp_init == PyTuple_Type.tp_init) &&
82 1 : !_PyArg_NoKeywords("tuple", kwargs)) {
83 1 : goto exit;
84 : }
85 7908050 : if (!_PyArg_CheckPositional("tuple", PyTuple_GET_SIZE(args), 0, 1)) {
86 0 : goto exit;
87 : }
88 7908050 : if (PyTuple_GET_SIZE(args) < 1) {
89 30 : goto skip_optional;
90 : }
91 7908020 : iterable = PyTuple_GET_ITEM(args, 0);
92 7908050 : skip_optional:
93 7908050 : return_value = tuple_new_impl(type, iterable);
94 :
95 7908050 : exit:
96 7908050 : return return_value;
97 : }
98 :
99 : PyDoc_STRVAR(tuple___getnewargs____doc__,
100 : "__getnewargs__($self, /)\n"
101 : "--\n"
102 : "\n");
103 :
104 : #define TUPLE___GETNEWARGS___METHODDEF \
105 : {"__getnewargs__", (PyCFunction)tuple___getnewargs__, METH_NOARGS, tuple___getnewargs____doc__},
106 :
107 : static PyObject *
108 : tuple___getnewargs___impl(PyTupleObject *self);
109 :
110 : static PyObject *
111 146 : tuple___getnewargs__(PyTupleObject *self, PyObject *Py_UNUSED(ignored))
112 : {
113 146 : return tuple___getnewargs___impl(self);
114 : }
115 : /*[clinic end generated code: output=044496dc917f8a97 input=a9049054013a1b77]*/
|