-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
gh-111262: Make PyDict_Pop() public #111263
Conversation
5674aa3
to
9c8539b
Compare
…have been public right away. See python#108449
9c8539b
to
16a95d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change lacks tests.
@@ -173,6 +173,16 @@ Dictionary Objects | |||
|
|||
.. versionadded:: 3.4 | |||
|
|||
|
|||
.. c:function:: PyObject* PyDict_Pop(PyObject *p, PyObject *key, PyObject *defaultobj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to return -1 on error, 0 if the key doesn't exist, 1 if the key exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would the caller know the popped value then?
{ | ||
if (!PyDict_Check(dict)) { | ||
PyErr_BadInternalCall(); | ||
return -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should certainly be return NULL
?
I created PR #111939 based on this PR: I changed the API and added tests. |
See #108449
I kept the internal function since it saves the type check on the fast path and can thus still be used internally.
📚 Documentation preview 📚: https://cpython-previews--111263.org.readthedocs.build/