• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 *
tuple_index(PyTupleObject * self,PyObject * const * args,Py_ssize_t nargs)23 tuple_index(PyTupleObject *self, PyObject *const *args, Py_ssize_t nargs)
24 {
25     PyObject *return_value = NULL;
26     PyObject *value;
27     Py_ssize_t start = 0;
28     Py_ssize_t stop = PY_SSIZE_T_MAX;
29 
30     if (!_PyArg_CheckPositional("index", nargs, 1, 3)) {
31         goto exit;
32     }
33     value = args[0];
34     if (nargs < 2) {
35         goto skip_optional;
36     }
37     if (!_PyEval_SliceIndexNotNone(args[1], &start)) {
38         goto exit;
39     }
40     if (nargs < 3) {
41         goto skip_optional;
42     }
43     if (!_PyEval_SliceIndexNotNone(args[2], &stop)) {
44         goto exit;
45     }
46 skip_optional:
47     return_value = tuple_index_impl(self, value, start, stop);
48 
49 exit:
50     return return_value;
51 }
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 PyDoc_STRVAR(tuple_new__doc__,
63 "tuple(iterable=(), /)\n"
64 "--\n"
65 "\n"
66 "Built-in immutable sequence.\n"
67 "\n"
68 "If no argument is given, the constructor returns an empty tuple.\n"
69 "If iterable is specified the tuple is initialized from iterable\'s items.\n"
70 "\n"
71 "If the argument is a tuple, the return value is the same object.");
72 
73 static PyObject *
74 tuple_new_impl(PyTypeObject *type, PyObject *iterable);
75 
76 static PyObject *
tuple_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)77 tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
78 {
79     PyObject *return_value = NULL;
80     PyTypeObject *base_tp = &PyTuple_Type;
81     PyObject *iterable = NULL;
82 
83     if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
84         !_PyArg_NoKeywords("tuple", kwargs)) {
85         goto exit;
86     }
87     if (!_PyArg_CheckPositional("tuple", PyTuple_GET_SIZE(args), 0, 1)) {
88         goto exit;
89     }
90     if (PyTuple_GET_SIZE(args) < 1) {
91         goto skip_optional;
92     }
93     iterable = PyTuple_GET_ITEM(args, 0);
94 skip_optional:
95     return_value = tuple_new_impl(type, iterable);
96 
97 exit:
98     return return_value;
99 }
100 
101 PyDoc_STRVAR(tuple___getnewargs____doc__,
102 "__getnewargs__($self, /)\n"
103 "--\n"
104 "\n");
105 
106 #define TUPLE___GETNEWARGS___METHODDEF    \
107     {"__getnewargs__", (PyCFunction)tuple___getnewargs__, METH_NOARGS, tuple___getnewargs____doc__},
108 
109 static PyObject *
110 tuple___getnewargs___impl(PyTupleObject *self);
111 
112 static PyObject *
tuple___getnewargs__(PyTupleObject * self,PyObject * Py_UNUSED (ignored))113 tuple___getnewargs__(PyTupleObject *self, PyObject *Py_UNUSED(ignored))
114 {
115     return tuple___getnewargs___impl(self);
116 }
117 /*[clinic end generated code: output=a6a9abba5d121f4c input=a9049054013a1b77]*/
118