I noticed that some functions like PyDict_GetItem(), PyDict_SetItem(), PyDict_DelItem(), etc has their variants that takes in a character array instead, but PyDict_Contains() does not.
I believe it should be added to add consistency and using PyUnicode_FromString(your_string_key) does work, but using PyDict_Contains(PyUnicode_FromString(your_string_key)) is a mouthful in my opinion.
Just consistency is not a strong reason to add this. Note that PyDict_Contains is more efficient as you can cache the unicode object; PyDict_ContainsString would need to allocate a unicode object and throw it away after it is done.
Thank you for the suggestion. As said above, consistency alone isn't enough to add and maintain a new function. While C API has some shortcuts, this use case should be fine with PyUnicode_FromString+PyDict_Contains.
I agree that it's a mouthful, but if you use it a lot, you can write your own helper function for it.
Activity
sobolevn commented on Dec 8, 2022
Adding things to CAPI would require to maintain this for many years: including tests / docs / etc. So, it needs a strong reasoning.
What's your usecase for this? Can you go around your problem by using PyUnicode_FromString(your_string_key)?
andrewhong04 commented on Dec 10, 2022
I believe it should be added to add consistency and using PyUnicode_FromString(your_string_key) does work, but using PyDict_Contains(PyUnicode_FromString(your_string_key)) is a mouthful in my opinion.
kumaraditya303 commented on Dec 10, 2022
Just consistency is not a strong reason to add this. Note that PyDict_Contains is more efficient as you can cache the unicode object; PyDict_ContainsString would need to allocate a unicode object and throw it away after it is done.
encukou commented on Dec 12, 2022
Thank you for the suggestion. As said above, consistency alone isn't enough to add and maintain a new function. While C API has some shortcuts, this use case should be fine with PyUnicode_FromString+PyDict_Contains.
I agree that it's a mouthful, but if you use it a lot, you can write your own helper function for it.