blob: 12f0df1d4393caab8915896d87ef4d9c58d95dfc [file] [log] [blame]
Serhiy Storchaka0b561592017-03-19 08:47:58 +02001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_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)tuple_index, METH_FASTCALL, tuple_index__doc__},
15
16static PyObject *
17tuple_index_impl(PyTupleObject *self, PyObject *value, Py_ssize_t start,
18 Py_ssize_t stop);
19
20static PyObject *
21tuple_index(PyTupleObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
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_ParseStack(args, nargs, "O|O&O&:index",
29 &value, _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &stop)) {
30 goto exit;
31 }
32
33 if (!_PyArg_NoStackKeywords("index", kwnames)) {
34 goto exit;
35 }
36 return_value = tuple_index_impl(self, value, start, stop);
37
38exit:
39 return return_value;
40}
41
42PyDoc_STRVAR(tuple_count__doc__,
43"count($self, value, /)\n"
44"--\n"
45"\n"
46"Return number of occurrences of value.");
47
48#define TUPLE_COUNT_METHODDEF \
49 {"count", (PyCFunction)tuple_count, METH_O, tuple_count__doc__},
50
51PyDoc_STRVAR(tuple_new__doc__,
52"tuple(iterable=(), /)\n"
53"--\n"
54"\n"
55"Built-in immutable sequence.\n"
56"\n"
57"If no argument is given, the constructor returns an empty tuple.\n"
58"If iterable is specified the tuple is initialized from iterable\'s items.\n"
59"\n"
60"If the argument is a tuple, the return value is the same object.");
61
62static PyObject *
63tuple_new_impl(PyTypeObject *type, PyObject *iterable);
64
65static PyObject *
66tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
67{
68 PyObject *return_value = NULL;
69 PyObject *iterable = NULL;
70
71 if ((type == &PyTuple_Type) &&
72 !_PyArg_NoKeywords("tuple", kwargs)) {
73 goto exit;
74 }
75 if (!PyArg_UnpackTuple(args, "tuple",
76 0, 1,
77 &iterable)) {
78 goto exit;
79 }
80 return_value = tuple_new_impl(type, iterable);
81
82exit:
83 return return_value;
84}
85
86PyDoc_STRVAR(tuple___getnewargs____doc__,
87"__getnewargs__($self, /)\n"
88"--\n"
89"\n");
90
91#define TUPLE___GETNEWARGS___METHODDEF \
92 {"__getnewargs__", (PyCFunction)tuple___getnewargs__, METH_NOARGS, tuple___getnewargs____doc__},
93
94static PyObject *
95tuple___getnewargs___impl(PyTupleObject *self);
96
97static PyObject *
98tuple___getnewargs__(PyTupleObject *self, PyObject *Py_UNUSED(ignored))
99{
100 return tuple___getnewargs___impl(self);
101}
102/*[clinic end generated code: output=561a3654411d2225 input=a9049054013a1b77]*/