[issue41871] Add PyList_Remove() in listobject.c

STINNER Victor report at bugs.python.org
Thu Oct 1 06:45:43 EDT 2020


STINNER Victor <vstinner at python.org> added the comment:

> it is more convenient to just call the method

Calling a Python method in Python is not convenient nor efficient.

For example, PyObject_CallMethod() has to decode a name from UTF-8 and then needs a lookup into the type dictionary. The list.remove() raises a exception if the item is not found, whereas PyCodec_Unregister() does nothing if the codec search function is not found: the exception is ignored.

It's also about correctness, looking for an item in a list can be tricky if the list size changes during the lookup, or Python can crash if it uses a borrowed reference whereas a list item is destroyed. There were tons of such bugs in the dict implementation. list.remove() doesn't look safe, but I would prefer to avoid having to fix the same bugs in copies of similar functions.

If a public function is not justified, what about an internal function?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41871>
_______________________________________


More information about the Python-bugs-list mailing list