Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

PyDict_GetItemString() is an old API from times when dicts could contain only 
string keys. It is not necessary part of the C API and can be replaced with 
PyDict_GetItem() in new code. It was kept only as a convenient function.

In issue35459 many uses of PyDict_GetItemString() were replaced with 
PyDict_GetItemWithError() and private _PyDict_GetItemIdWithError(). Only 4 
occurrences were replaced with newly added private 
_PyDict_GetItemStringWithError(). And they could use PyDict_GetItem(). So there 
are not much use cases for PyDict_GetItemStringWithError().

Before adding PyDict_GetItemStringWithError() we could consider alternatives.

*WithError() functions require calling PyErr_Occurred() to distinguish the 
error case from the "not found" case. This adds an overhead which can be not 
small in performance critical code. It would be better if the API function 
returned a three-state value: "found", "not found" and "error". See for example 
_PyObject_LookupAttr(). I am not sure this is the best design.

----------
dependencies: +Document C API functions which swallow exceptions
nosy: +serhiy.storchaka

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue35460>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to