tupleobject.c.h 3.1 KB

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