Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PyDict_ContainsString() #100100

Closed
novialriptide opened this issue Dec 8, 2022 · 4 comments
Closed

Add PyDict_ContainsString() #100100

novialriptide opened this issue Dec 8, 2022 · 4 comments
Labels
topic-C-API type-feature A feature request or enhancement

Comments

@novialriptide
Copy link
Contributor

novialriptide commented Dec 8, 2022

Feature or enhancement

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.

@novialriptide novialriptide added the type-feature A feature request or enhancement label Dec 8, 2022
@sobolevn
Copy link
Member

sobolevn commented 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)?

@novialriptide
Copy link
Contributor Author

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
Copy link
Contributor

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.

@sobolevn sobolevn added the pending The issue will be closed if no feedback is provided label Dec 10, 2022
@encukou
Copy link
Member

encukou commented 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.

@encukou encukou closed this as not planned Won't fix, can't repro, duplicate, stale Dec 12, 2022
@erlend-aasland erlend-aasland removed the pending The issue will be closed if no feedback is provided label Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-C-API type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

6 participants