[Enhancement] Expose list.remove() as PyList_Remove(PyObject *) in the C API.
Proposal:
Currently for C extension devs if they over-allocate a list, and then realize later in a loop after checking using some if's that not every entry is filled and some of them as NULL one might want to directly call the api function to remove any and every item inside the list object that is still NULL. I have looked inside the code and noticed that the same implementation for list.removein the python code side can be reused for this without issues and as such should be a minor change except for the new api function that would be added to the public api and export from pythonXY.dll/pythonXY.so/pythonXY.dylib.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Such an API was proposed a few years ago but rejected:
- #86037
ISTM that the C API should remain low level for two reasons.
-
There is already an API for C code to call anything that can be called from pure python. It adds a tiny amount of overhead but that only matters for fine-grained functions that tend to be called in a loop. Course grained functions that are already
O(n)don't see any real benefit. -
Almost the entire point of writing C code is that you want something different than what pure python gives you. For the most part, you want a low-level API so you can efficiently implement your own customizations (for example, remove-variants that return a flag rather than raising an exception, a single-pass multi-remove, or a right-to-left remove).
You can already call PyObject_CallMethod(your_list, "remove", "O", object_to_remove). I don't think that such function call is common enough to justify adding a C API for it.
I close the issue since it's inactive for almost a year and comments are towards rejecting the feature request.
By the way, list.remove(x) has a complexity of O(n). I'm not sure that it's a good idea to "promote" such function in the C API.
Sorry @AraHaan ;-)