[issue35438] Cleanup extension functions using _PyObject_LookupSpecial
Serhiy Storchaka
report at bugs.python.org
Mon Dec 10 14:25:08 EST 2018
Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:
There is nothing wrong with using private C API in the implementation of standard CPython extensions. This API was designed for this.
In contrary, there are problems with your code:
* It is less efficient. String objects are created and destroyed twice per every function call, in PyObject_HasAttrString() and in PyObject_CallMethod(). Format string is parsed in PyObject_CallMethod(). Other temporary objects are created and destroyed.
* It uses inherently broken PyObject_HasAttrString(). PyObject_HasAttrString() swallows exceptions (for example a MemoryError raised when create a temporary string object) and can return an incorrect result.
* It is not equivalent with the existing code. For example it does not work properly if the dunder method is a static method.
----------
nosy: +serhiy.storchaka
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35438>
_______________________________________
More information about the Python-bugs-list
mailing list