/src/Python-3.8.3/Objects/clinic/tupleobject.c.h
Line | Count | Source (jump to first uncovered line) |
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 * |
21 | | tuple_index(PyTupleObject *self, PyObject *const *args, Py_ssize_t nargs) |
22 | 0 | { |
23 | 0 | PyObject *return_value = NULL; |
24 | 0 | PyObject *value; |
25 | 0 | Py_ssize_t start = 0; |
26 | 0 | Py_ssize_t stop = PY_SSIZE_T_MAX; |
27 | |
|
28 | 0 | if (!_PyArg_CheckPositional("index", nargs, 1, 3)) { |
29 | 0 | goto exit; |
30 | 0 | } |
31 | 0 | value = args[0]; |
32 | 0 | if (nargs < 2) { |
33 | 0 | goto skip_optional; |
34 | 0 | } |
35 | 0 | if (!_PyEval_SliceIndexNotNone(args[1], &start)) { |
36 | 0 | goto exit; |
37 | 0 | } |
38 | 0 | if (nargs < 3) { |
39 | 0 | goto skip_optional; |
40 | 0 | } |
41 | 0 | if (!_PyEval_SliceIndexNotNone(args[2], &stop)) { |
42 | 0 | goto exit; |
43 | 0 | } |
44 | 0 | skip_optional: |
45 | 0 | return_value = tuple_index_impl(self, value, start, stop); |
46 | |
|
47 | 0 | exit: |
48 | 0 | return return_value; |
49 | 0 | } |
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 | | tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
76 | 307 | { |
77 | 307 | PyObject *return_value = NULL; |
78 | 307 | PyObject *iterable = NULL; |
79 | | |
80 | 307 | if ((type == &PyTuple_Type) && |
81 | 307 | !_PyArg_NoKeywords("tuple", kwargs)) { |
82 | 0 | goto exit; |
83 | 0 | } |
84 | 307 | if (!_PyArg_CheckPositional("tuple", PyTuple_GET_SIZE(args), 0, 1)) { |
85 | 0 | goto exit; |
86 | 0 | } |
87 | 307 | if (PyTuple_GET_SIZE(args) < 1) { |
88 | 0 | goto skip_optional; |
89 | 0 | } |
90 | 307 | iterable = PyTuple_GET_ITEM(args, 0); |
91 | 307 | skip_optional: |
92 | 307 | return_value = tuple_new_impl(type, iterable); |
93 | | |
94 | 307 | exit: |
95 | 307 | return return_value; |
96 | 307 | } |
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 * |
110 | | tuple___getnewargs__(PyTupleObject *self, PyObject *Py_UNUSED(ignored)) |
111 | 0 | { |
112 | 0 | return tuple___getnewargs___impl(self); |
113 | 0 | } |
114 | | /*[clinic end generated code: output=56fab9b7368aba49 input=a9049054013a1b77]*/ |