(root)/
Python-3.12.0/
Objects/
clinic/
tupleobject.c.h
       1  /*[clinic input]
       2  preserve
       3  [clinic start generated code]*/
       4  
       5  #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
       6  #  include "pycore_gc.h"            // PyGC_Head
       7  #  include "pycore_runtime.h"       // _Py_ID()
       8  #endif
       9  
      10  
      11  PyDoc_STRVAR(tuple_index__doc__,
      12  "index($self, value, start=0, stop=sys.maxsize, /)\n"
      13  "--\n"
      14  "\n"
      15  "Return first index of value.\n"
      16  "\n"
      17  "Raises ValueError if the value is not present.");
      18  
      19  #define TUPLE_INDEX_METHODDEF    \
      20      {"index", _PyCFunction_CAST(tuple_index), METH_FASTCALL, tuple_index__doc__},
      21  
      22  static PyObject *
      23  tuple_index_impl(PyTupleObject *self, PyObject *value, Py_ssize_t start,
      24                   Py_ssize_t stop);
      25  
      26  static PyObject *
      27  tuple_index(PyTupleObject *self, PyObject *const *args, Py_ssize_t nargs)
      28  {
      29      PyObject *return_value = NULL;
      30      PyObject *value;
      31      Py_ssize_t start = 0;
      32      Py_ssize_t stop = PY_SSIZE_T_MAX;
      33  
      34      if (!_PyArg_CheckPositional("index", nargs, 1, 3)) {
      35          goto exit;
      36      }
      37      value = args[0];
      38      if (nargs < 2) {
      39          goto skip_optional;
      40      }
      41      if (!_PyEval_SliceIndexNotNone(args[1], &start)) {
      42          goto exit;
      43      }
      44      if (nargs < 3) {
      45          goto skip_optional;
      46      }
      47      if (!_PyEval_SliceIndexNotNone(args[2], &stop)) {
      48          goto exit;
      49      }
      50  skip_optional:
      51      return_value = tuple_index_impl(self, value, start, stop);
      52  
      53  exit:
      54      return return_value;
      55  }
      56  
      57  PyDoc_STRVAR(tuple_count__doc__,
      58  "count($self, value, /)\n"
      59  "--\n"
      60  "\n"
      61  "Return number of occurrences of value.");
      62  
      63  #define TUPLE_COUNT_METHODDEF    \
      64      {"count", (PyCFunction)tuple_count, METH_O, tuple_count__doc__},
      65  
      66  PyDoc_STRVAR(tuple_new__doc__,
      67  "tuple(iterable=(), /)\n"
      68  "--\n"
      69  "\n"
      70  "Built-in immutable sequence.\n"
      71  "\n"
      72  "If no argument is given, the constructor returns an empty tuple.\n"
      73  "If iterable is specified the tuple is initialized from iterable\'s items.\n"
      74  "\n"
      75  "If the argument is a tuple, the return value is the same object.");
      76  
      77  static PyObject *
      78  tuple_new_impl(PyTypeObject *type, PyObject *iterable);
      79  
      80  static PyObject *
      81  tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
      82  {
      83      PyObject *return_value = NULL;
      84      PyTypeObject *base_tp = &PyTuple_Type;
      85      PyObject *iterable = NULL;
      86  
      87      if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
      88          !_PyArg_NoKeywords("tuple", kwargs)) {
      89          goto exit;
      90      }
      91      if (!_PyArg_CheckPositional("tuple", PyTuple_GET_SIZE(args), 0, 1)) {
      92          goto exit;
      93      }
      94      if (PyTuple_GET_SIZE(args) < 1) {
      95          goto skip_optional;
      96      }
      97      iterable = PyTuple_GET_ITEM(args, 0);
      98  skip_optional:
      99      return_value = tuple_new_impl(type, iterable);
     100  
     101  exit:
     102      return return_value;
     103  }
     104  
     105  PyDoc_STRVAR(tuple___getnewargs____doc__,
     106  "__getnewargs__($self, /)\n"
     107  "--\n"
     108  "\n");
     109  
     110  #define TUPLE___GETNEWARGS___METHODDEF    \
     111      {"__getnewargs__", (PyCFunction)tuple___getnewargs__, METH_NOARGS, tuple___getnewargs____doc__},
     112  
     113  static PyObject *
     114  tuple___getnewargs___impl(PyTupleObject *self);
     115  
     116  static PyObject *
     117  tuple___getnewargs__(PyTupleObject *self, PyObject *Py_UNUSED(ignored))
     118  {
     119      return tuple___getnewargs___impl(self);
     120  }
     121  /*[clinic end generated code: output=48a9e0834b300ac3 input=a9049054013a1b77]*/