diff options
author | Victor Stinner <vstinner@python.org> | 2023-11-13 16:14:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-13 16:14:56 (GMT) |
commit | babb787047e0f7807c8238d3b1a3128dac30bd5c (patch) | |
tree | 868cd78ee07ef9c20a5af32db79f979c543b8f0e /Doc | |
parent | 29af7369dbbbba8cefafb196e977bce8189a527d (diff) | |
download | cpython-babb787047e0f7807c8238d3b1a3128dac30bd5c.zip cpython-babb787047e0f7807c8238d3b1a3128dac30bd5c.tar.gz cpython-babb787047e0f7807c8238d3b1a3128dac30bd5c.tar.bz2 |
gh-111138: Add PyList_Extend() and PyList_Clear() functions (#111862)
* Split list_extend() into two sub-functions: list_extend_fast() and
list_extend_iter().
* list_inplace_concat() no longer has to call Py_DECREF() on the
list_extend() result, since list_extend() now returns an int.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/c-api/list.rst | 24 | ||||
-rw-r--r-- | Doc/whatsnew/3.13.rst | 4 |
2 files changed, 28 insertions, 0 deletions
diff --git a/Doc/c-api/list.rst b/Doc/c-api/list.rst index c15cecd..c8b64ba 100644 --- a/Doc/c-api/list.rst +++ b/Doc/c-api/list.rst @@ -128,6 +128,30 @@ List Objects list is not supported. +.. c:function:: int PyList_Extend(PyObject *list, PyObject *iterable) + + Extend *list* with the contents of *iterable*. This is the same as + ``PyList_SetSlice(list, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, iterable)`` + and analogous to ``list.extend(iterable)`` or ``list += iterable``. + + Raise an exception and return ``-1`` if *list* is not a :class:`list` + object. Return 0 on success. + + .. versionadded:: 3.13 + + +.. c:function:: int PyList_Clear(PyObject *list) + + Remove all items from *list*. This is the same as + ``PyList_SetSlice(list, 0, PY_SSIZE_T_MAX, NULL)`` and analogous to + ``list.clear()`` or ``del list[:]``. + + Raise an exception and return ``-1`` if *list* is not a :class:`list` + object. Return 0 on success. + + .. versionadded:: 3.13 + + .. c:function:: int PyList_Sort(PyObject *list) Sort the items of *list* in place. Return ``0`` on success, ``-1`` on diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index ae3c88d..9f9239a 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -1164,6 +1164,10 @@ New Features :c:func:`PyErr_WriteUnraisable`, but allow to customize the warning mesage. (Contributed by Serhiy Storchaka in :gh:`108082`.) +* Add :c:func:`PyList_Extend` and :c:func:`PyList_Clear` functions: similar to + Python ``list.extend()`` and ``list.clear()`` methods. + (Contributed by Victor Stinner in :gh:`111138`.) + Porting to Python 3.13 ---------------------- |