(root)/
Python-3.11.7/
Objects/
clinic/
listobject.c.h
       1  /*[clinic input]
       2  preserve
       3  [clinic start generated code]*/
       4  
       5  PyDoc_STRVAR(list_insert__doc__,
       6  "insert($self, index, object, /)\n"
       7  "--\n"
       8  "\n"
       9  "Insert object before index.");
      10  
      11  #define LIST_INSERT_METHODDEF    \
      12      {"insert", _PyCFunction_CAST(list_insert), METH_FASTCALL, list_insert__doc__},
      13  
      14  static PyObject *
      15  list_insert_impl(PyListObject *self, Py_ssize_t index, PyObject *object);
      16  
      17  static PyObject *
      18  list_insert(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
      19  {
      20      PyObject *return_value = NULL;
      21      Py_ssize_t index;
      22      PyObject *object;
      23  
      24      if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) {
      25          goto exit;
      26      }
      27      {
      28          Py_ssize_t ival = -1;
      29          PyObject *iobj = _PyNumber_Index(args[0]);
      30          if (iobj != NULL) {
      31              ival = PyLong_AsSsize_t(iobj);
      32              Py_DECREF(iobj);
      33          }
      34          if (ival == -1 && PyErr_Occurred()) {
      35              goto exit;
      36          }
      37          index = ival;
      38      }
      39      object = args[1];
      40      return_value = list_insert_impl(self, index, object);
      41  
      42  exit:
      43      return return_value;
      44  }
      45  
      46  PyDoc_STRVAR(list_clear__doc__,
      47  "clear($self, /)\n"
      48  "--\n"
      49  "\n"
      50  "Remove all items from list.");
      51  
      52  #define LIST_CLEAR_METHODDEF    \
      53      {"clear", (PyCFunction)list_clear, METH_NOARGS, list_clear__doc__},
      54  
      55  static PyObject *
      56  list_clear_impl(PyListObject *self);
      57  
      58  static PyObject *
      59  list_clear(PyListObject *self, PyObject *Py_UNUSED(ignored))
      60  {
      61      return list_clear_impl(self);
      62  }
      63  
      64  PyDoc_STRVAR(list_copy__doc__,
      65  "copy($self, /)\n"
      66  "--\n"
      67  "\n"
      68  "Return a shallow copy of the list.");
      69  
      70  #define LIST_COPY_METHODDEF    \
      71      {"copy", (PyCFunction)list_copy, METH_NOARGS, list_copy__doc__},
      72  
      73  static PyObject *
      74  list_copy_impl(PyListObject *self);
      75  
      76  static PyObject *
      77  list_copy(PyListObject *self, PyObject *Py_UNUSED(ignored))
      78  {
      79      return list_copy_impl(self);
      80  }
      81  
      82  PyDoc_STRVAR(list_append__doc__,
      83  "append($self, object, /)\n"
      84  "--\n"
      85  "\n"
      86  "Append object to the end of the list.");
      87  
      88  #define LIST_APPEND_METHODDEF    \
      89      {"append", (PyCFunction)list_append, METH_O, list_append__doc__},
      90  
      91  PyDoc_STRVAR(list_extend__doc__,
      92  "extend($self, iterable, /)\n"
      93  "--\n"
      94  "\n"
      95  "Extend list by appending elements from the iterable.");
      96  
      97  #define LIST_EXTEND_METHODDEF    \
      98      {"extend", (PyCFunction)list_extend, METH_O, list_extend__doc__},
      99  
     100  PyDoc_STRVAR(list_pop__doc__,
     101  "pop($self, index=-1, /)\n"
     102  "--\n"
     103  "\n"
     104  "Remove and return item at index (default last).\n"
     105  "\n"
     106  "Raises IndexError if list is empty or index is out of range.");
     107  
     108  #define LIST_POP_METHODDEF    \
     109      {"pop", _PyCFunction_CAST(list_pop), METH_FASTCALL, list_pop__doc__},
     110  
     111  static PyObject *
     112  list_pop_impl(PyListObject *self, Py_ssize_t index);
     113  
     114  static PyObject *
     115  list_pop(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
     116  {
     117      PyObject *return_value = NULL;
     118      Py_ssize_t index = -1;
     119  
     120      if (!_PyArg_CheckPositional("pop", nargs, 0, 1)) {
     121          goto exit;
     122      }
     123      if (nargs < 1) {
     124          goto skip_optional;
     125      }
     126      {
     127          Py_ssize_t ival = -1;
     128          PyObject *iobj = _PyNumber_Index(args[0]);
     129          if (iobj != NULL) {
     130              ival = PyLong_AsSsize_t(iobj);
     131              Py_DECREF(iobj);
     132          }
     133          if (ival == -1 && PyErr_Occurred()) {
     134              goto exit;
     135          }
     136          index = ival;
     137      }
     138  skip_optional:
     139      return_value = list_pop_impl(self, index);
     140  
     141  exit:
     142      return return_value;
     143  }
     144  
     145  PyDoc_STRVAR(list_sort__doc__,
     146  "sort($self, /, *, key=None, reverse=False)\n"
     147  "--\n"
     148  "\n"
     149  "Sort the list in ascending order and return None.\n"
     150  "\n"
     151  "The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n"
     152  "order of two equal elements is maintained).\n"
     153  "\n"
     154  "If a key function is given, apply it once to each list item and sort them,\n"
     155  "ascending or descending, according to their function values.\n"
     156  "\n"
     157  "The reverse flag can be set to sort in descending order.");
     158  
     159  #define LIST_SORT_METHODDEF    \
     160      {"sort", _PyCFunction_CAST(list_sort), METH_FASTCALL|METH_KEYWORDS, list_sort__doc__},
     161  
     162  static PyObject *
     163  list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse);
     164  
     165  static PyObject *
     166  list_sort(PyListObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     167  {
     168      PyObject *return_value = NULL;
     169      static const char * const _keywords[] = {"key", "reverse", NULL};
     170      static _PyArg_Parser _parser = {NULL, _keywords, "sort", 0};
     171      PyObject *argsbuf[2];
     172      Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
     173      PyObject *keyfunc = Py_None;
     174      int reverse = 0;
     175  
     176      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
     177      if (!args) {
     178          goto exit;
     179      }
     180      if (!noptargs) {
     181          goto skip_optional_kwonly;
     182      }
     183      if (args[0]) {
     184          keyfunc = args[0];
     185          if (!--noptargs) {
     186              goto skip_optional_kwonly;
     187          }
     188      }
     189      reverse = _PyLong_AsInt(args[1]);
     190      if (reverse == -1 && PyErr_Occurred()) {
     191          goto exit;
     192      }
     193  skip_optional_kwonly:
     194      return_value = list_sort_impl(self, keyfunc, reverse);
     195  
     196  exit:
     197      return return_value;
     198  }
     199  
     200  PyDoc_STRVAR(list_reverse__doc__,
     201  "reverse($self, /)\n"
     202  "--\n"
     203  "\n"
     204  "Reverse *IN PLACE*.");
     205  
     206  #define LIST_REVERSE_METHODDEF    \
     207      {"reverse", (PyCFunction)list_reverse, METH_NOARGS, list_reverse__doc__},
     208  
     209  static PyObject *
     210  list_reverse_impl(PyListObject *self);
     211  
     212  static PyObject *
     213  list_reverse(PyListObject *self, PyObject *Py_UNUSED(ignored))
     214  {
     215      return list_reverse_impl(self);
     216  }
     217  
     218  PyDoc_STRVAR(list_index__doc__,
     219  "index($self, value, start=0, stop=sys.maxsize, /)\n"
     220  "--\n"
     221  "\n"
     222  "Return first index of value.\n"
     223  "\n"
     224  "Raises ValueError if the value is not present.");
     225  
     226  #define LIST_INDEX_METHODDEF    \
     227      {"index", _PyCFunction_CAST(list_index), METH_FASTCALL, list_index__doc__},
     228  
     229  static PyObject *
     230  list_index_impl(PyListObject *self, PyObject *value, Py_ssize_t start,
     231                  Py_ssize_t stop);
     232  
     233  static PyObject *
     234  list_index(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
     235  {
     236      PyObject *return_value = NULL;
     237      PyObject *value;
     238      Py_ssize_t start = 0;
     239      Py_ssize_t stop = PY_SSIZE_T_MAX;
     240  
     241      if (!_PyArg_CheckPositional("index", nargs, 1, 3)) {
     242          goto exit;
     243      }
     244      value = args[0];
     245      if (nargs < 2) {
     246          goto skip_optional;
     247      }
     248      if (!_PyEval_SliceIndexNotNone(args[1], &start)) {
     249          goto exit;
     250      }
     251      if (nargs < 3) {
     252          goto skip_optional;
     253      }
     254      if (!_PyEval_SliceIndexNotNone(args[2], &stop)) {
     255          goto exit;
     256      }
     257  skip_optional:
     258      return_value = list_index_impl(self, value, start, stop);
     259  
     260  exit:
     261      return return_value;
     262  }
     263  
     264  PyDoc_STRVAR(list_count__doc__,
     265  "count($self, value, /)\n"
     266  "--\n"
     267  "\n"
     268  "Return number of occurrences of value.");
     269  
     270  #define LIST_COUNT_METHODDEF    \
     271      {"count", (PyCFunction)list_count, METH_O, list_count__doc__},
     272  
     273  PyDoc_STRVAR(list_remove__doc__,
     274  "remove($self, value, /)\n"
     275  "--\n"
     276  "\n"
     277  "Remove first occurrence of value.\n"
     278  "\n"
     279  "Raises ValueError if the value is not present.");
     280  
     281  #define LIST_REMOVE_METHODDEF    \
     282      {"remove", (PyCFunction)list_remove, METH_O, list_remove__doc__},
     283  
     284  PyDoc_STRVAR(list___init____doc__,
     285  "list(iterable=(), /)\n"
     286  "--\n"
     287  "\n"
     288  "Built-in mutable sequence.\n"
     289  "\n"
     290  "If no argument is given, the constructor creates a new empty list.\n"
     291  "The argument must be an iterable if specified.");
     292  
     293  static int
     294  list___init___impl(PyListObject *self, PyObject *iterable);
     295  
     296  static int
     297  list___init__(PyObject *self, PyObject *args, PyObject *kwargs)
     298  {
     299      int return_value = -1;
     300      PyObject *iterable = NULL;
     301  
     302      if ((Py_IS_TYPE(self, &PyList_Type) ||
     303           Py_TYPE(self)->tp_new == PyList_Type.tp_new) &&
     304          !_PyArg_NoKeywords("list", kwargs)) {
     305          goto exit;
     306      }
     307      if (!_PyArg_CheckPositional("list", PyTuple_GET_SIZE(args), 0, 1)) {
     308          goto exit;
     309      }
     310      if (PyTuple_GET_SIZE(args) < 1) {
     311          goto skip_optional;
     312      }
     313      iterable = PyTuple_GET_ITEM(args, 0);
     314  skip_optional:
     315      return_value = list___init___impl((PyListObject *)self, iterable);
     316  
     317  exit:
     318      return return_value;
     319  }
     320  
     321  PyDoc_STRVAR(list___sizeof____doc__,
     322  "__sizeof__($self, /)\n"
     323  "--\n"
     324  "\n"
     325  "Return the size of the list in memory, in bytes.");
     326  
     327  #define LIST___SIZEOF___METHODDEF    \
     328      {"__sizeof__", (PyCFunction)list___sizeof__, METH_NOARGS, list___sizeof____doc__},
     329  
     330  static PyObject *
     331  list___sizeof___impl(PyListObject *self);
     332  
     333  static PyObject *
     334  list___sizeof__(PyListObject *self, PyObject *Py_UNUSED(ignored))
     335  {
     336      return list___sizeof___impl(self);
     337  }
     338  
     339  PyDoc_STRVAR(list___reversed____doc__,
     340  "__reversed__($self, /)\n"
     341  "--\n"
     342  "\n"
     343  "Return a reverse iterator over the list.");
     344  
     345  #define LIST___REVERSED___METHODDEF    \
     346      {"__reversed__", (PyCFunction)list___reversed__, METH_NOARGS, list___reversed____doc__},
     347  
     348  static PyObject *
     349  list___reversed___impl(PyListObject *self);
     350  
     351  static PyObject *
     352  list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored))
     353  {
     354      return list___reversed___impl(self);
     355  }
     356  /*[clinic end generated code: output=eab97a76b1568a03 input=a9049054013a1b77]*/