◐ Shell
clean mode source ↗

gh-106320: Remove private _PyType_Lookup() function by vstinner · Pull Request #108600 · python/cpython

Which aspects of the API you would like to change in _PyType_Lookup()?

First of all, it contains PyErr_Clear(). We should get rid of such functions.

If it start returning an error, there are variants of the interface: return a pointer with the following calling of PyErr_Occurred() if it is NULL, or return -1/0/1 and save the reference by provided pointer like in PyObject_GetOptionalAttr(), or return a pointer and set the error flag by provided pointer like in find_name_in_mro() and some other private function. It can also return in what type the name was found if there is a need.

Then you may want to return a new reference, although I am not sure that there is a problem with a borrowing reference here. But we should investigate.

It may be turn out that _PyType_Lookup() is too low level, and that all use cases can be covered by few higher level wrappers. Then we can even remove it from internal API.