-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
[C API] Add PyDict_ContainsString() function #108314
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
Labels
Comments
vstinner
added a commit
to vstinner/cpython
that referenced
this issue
Aug 22, 2023
Use PyDict_ContainsString() in pylifecycle.c and pythonrun.c.
vstinner
added a commit
to vstinner/cpython
that referenced
this issue
Aug 22, 2023
Use PyDict_ContainsString() in pylifecycle.c and pythonrun.c.
vstinner
added a commit
to vstinner/cpython
that referenced
this issue
Aug 22, 2023
Use PyDict_ContainsString() in pylifecycle.c and pythonrun.c.
There is already an abstract PyMapping_HasKeyString() function. Sadly, on error, this function clears the exception and returns 0 :-( |
FYI, there was the discussion with adding this API. |
And here: #100100 |
vstinner
added a commit
to vstinner/cpython
that referenced
this issue
Aug 23, 2023
* The new function is not part of the limited C API. * Use PyDict_ContainsString() in pylifecycle.c and pythonrun.c.
vstinner
added a commit
that referenced
this issue
Aug 24, 2023
vstinner
added a commit
to vstinner/cpython
that referenced
this issue
Aug 24, 2023
PyDict_GetItemString(), PyDict_SetItemString() and PyDict_DelItemString() expects a UTF-8 encoding string for the key.
I added the function to pythoncapi-compat: python/pythoncapi-compat@4734c8e |
Yhg1s
pushed a commit
that referenced
this issue
Aug 25, 2023
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
Aug 25, 2023
…GH-108448) pythongh-108314: PyDict_GetItemString() mentions UTF-8 PyDict_GetItemString(), PyDict_SetItemString() and PyDict_DelItemString() expects a UTF-8 encoding string for the key. (cherry picked from commit 9a225d7) Co-authored-by: Victor Stinner <[email protected]>
vstinner
added a commit
that referenced
this issue
Aug 25, 2023
…8448) (#108489) [3.12] gh-108314: PyDict_GetItemString() mentions UTF-8 (GH-108448) gh-108314: PyDict_GetItemString() mentions UTF-8 PyDict_GetItemString(), PyDict_SetItemString() and PyDict_DelItemString() expects a UTF-8 encoding string for the key. (cherry picked from commit 9a225d7) Co-authored-by: Victor Stinner <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Feature or enhancement
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Proposal:
Most, if not all, PyDict C APIs have a "String" flavor where the key argument is expressed as a UTF-8 encoded bytes string. But the
PyDict_Contains()
API is missing such variant.I suppose that it was not proposed before since
PyDict_GetItemString(dict, key) != NULL
can already be used. My problem is thatPyDict_GetItemString()
ignores errors: I would like to report errors.The newly added
PyDict_GetItemStringRef()
can be used to check if a dictionary has a key and report errors, but it requires callingPy_DECREF()
which is not convenient. Example:I would like to be able to replace this code with:
There is no need to INCREF/DECREF just to check if a dictionary has a key.
Linked PRs
The text was updated successfully, but these errors were encountered: