Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Expose list.remove() as PyList_Remove(PyObject *) in the C API. #119133

Open
AraHaan opened this issue May 17, 2024 · 2 comments
Open
Labels
topic-C-API type-feature A feature request or enhancement

Comments

@AraHaan
Copy link
Contributor

AraHaan commented May 17, 2024

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

@AraHaan AraHaan added the type-feature A feature request or enhancement label May 17, 2024
@erlend-aasland
Copy link
Contributor

Such an API was proposed a few years ago but rejected:

@vstinner vstinner changed the title [Enhancement] Expose List.Remove as PyList_Remove(PyObject *) in the C API. [Enhancement] Expose list.remove() as PyList_Remove(PyObject *) in the C API. May 20, 2024
@rhettinger
Copy link
Contributor

ISTM that the C API should remain low level for two reasons.

  1. 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.

  2. 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-C-API type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants