You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
The private _PyList_Extend() function has been removed in Python 3.13: see PR #108451.
@scoderasked what is the replacement for this removed function.
The obvious replacement is PyObject_CallMethod(list, "extend", "O", arg): call the list.extend() method. But it's slower, PyObject_CallMethod() has to get the method and decode the "O" format string.
Another replacement is PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, arg) which is less straightforward, but it's efficient.
I propose adding a public PyList_Extend() function. The list type is commonly used in C extensions, it's a convenient API to create a collection when the length is not known is advance.
I don't think that performance is really the problem here since PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, arg) is available. The problem is more to more the function easier to discover and make the API easier to use. Also, it should help people to migrate away from the removed function.
There is already a public PyDict_Update() API for the dict type, it is part of the limited C API.
If we add a function for the list type, should we also add PySet_Update() "for completeness"? The private _PySet_Update() was removed in Python 3.13.
vstinner
changed the title
C API: Consider adding a public PyList_Extend() function to replace removed private _PyList_Extend()
C API: Consider adding a public PyList_Extend() function
Oct 20, 2023
Feature or enhancement
The private
_PyList_Extend()function has been removed in Python 3.13: see PR #108451.@scoder asked what is the replacement for this removed function.
The obvious replacement is
PyObject_CallMethod(list, "extend", "O", arg): call thelist.extend()method. But it's slower,PyObject_CallMethod()has to get the method and decode the "O" format string.Another replacement is
PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, arg)which is less straightforward, but it's efficient.I propose adding a public PyList_Extend() function. The list type is commonly used in C extensions, it's a convenient API to create a collection when the length is not known is advance.
I don't think that performance is really the problem here since
PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, arg)is available. The problem is more to more the function easier to discover and make the API easier to use. Also, it should help people to migrate away from the removed function.There is already a public PyDict_Update() API for the dict type, it is part of the limited C API.
If we add a function for the list type, should we also add PySet_Update() "for completeness"? The private
_PySet_Update()was removed in Python 3.13.cc @serhiy-storchaka @encukou
A code search on
_PyList_Extendin PyPI top 5,000 projects (2023-07-04) found 4 projects using this function:Logs:
Cython uses the function to implement its own __Pyx_PyList_Extend() API:
The text was updated successfully, but these errors were encountered: