blob: 67d9f340e083b813be6b449adb75a0dc26f37b9c [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 \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020014 {"index", (PyCFunction)(void(*)(void))tuple_index, METH_FASTCALL, tuple_index__doc__},
Serhiy Storchaka0b561592017-03-19 08:47:58 +020015
16static PyObject *
17tuple_index_impl(PyTupleObject *self, PyObject *value, Py_ssize_t start,
18 Py_ssize_t stop);
19
20static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020021tuple_index(PyTupleObject *self, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0b561592017-03-19 08:47:58 +020022{
23 PyObject *return_value = NULL;
24 PyObject *value;
25 Py_ssize_t start = 0;
26 Py_ssize_t stop = PY_SSIZE_T_MAX;
27
Sylvain74453812017-06-10 06:51:48 +020028 if (!_PyArg_ParseStack(args, nargs, "O|O&O&:index",
29 &value, _PyEval_SliceIndexNotNone, &start, _PyEval_SliceIndexNotNone, &stop)) {
Serhiy Storchaka0b561592017-03-19 08:47:58 +020030 goto exit;
31 }
32 return_value = tuple_index_impl(self, value, start, stop);
33
34exit:
35 return return_value;
36}
37
38PyDoc_STRVAR(tuple_count__doc__,
39"count($self, value, /)\n"
40"--\n"
41"\n"
42"Return number of occurrences of value.");
43
44#define TUPLE_COUNT_METHODDEF \
45 {"count", (PyCFunction)tuple_count, METH_O, tuple_count__doc__},
46
47PyDoc_STRVAR(tuple_new__doc__,
48"tuple(iterable=(), /)\n"
49"--\n"
50"\n"
51"Built-in immutable sequence.\n"
52"\n"
53"If no argument is given, the constructor returns an empty tuple.\n"
54"If iterable is specified the tuple is initialized from iterable\'s items.\n"
55"\n"
56"If the argument is a tuple, the return value is the same object.");
57
58static PyObject *
59tuple_new_impl(PyTypeObject *type, PyObject *iterable);
60
61static PyObject *
62tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
63{
64 PyObject *return_value = NULL;
65 PyObject *iterable = NULL;
66
67 if ((type == &PyTuple_Type) &&
68 !_PyArg_NoKeywords("tuple", kwargs)) {
69 goto exit;
70 }
71 if (!PyArg_UnpackTuple(args, "tuple",
72 0, 1,
73 &iterable)) {
74 goto exit;
75 }
76 return_value = tuple_new_impl(type, iterable);
77
78exit:
79 return return_value;
80}
81
82PyDoc_STRVAR(tuple___getnewargs____doc__,
83"__getnewargs__($self, /)\n"
84"--\n"
85"\n");
86
87#define TUPLE___GETNEWARGS___METHODDEF \
88 {"__getnewargs__", (PyCFunction)tuple___getnewargs__, METH_NOARGS, tuple___getnewargs____doc__},
89
90static PyObject *
91tuple___getnewargs___impl(PyTupleObject *self);
92
93static PyObject *
94tuple___getnewargs__(PyTupleObject *self, PyObject *Py_UNUSED(ignored))
95{
96 return tuple___getnewargs___impl(self);
97}
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020098/*[clinic end generated code: output=0a6ebd2d16b09c5d input=a9049054013a1b77]*/