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

gh-111262: Make PyDict_Pop() public #111263

Closed
wants to merge 1 commit into from
Closed

Conversation

scoder
Copy link
Contributor

@scoder scoder commented Oct 24, 2023

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/

@scoder
Copy link
Contributor Author

scoder commented Oct 24, 2023

@vstinner

@brandtbucher brandtbucher added type-feature A feature request or enhancement interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-C-API labels Oct 24, 2023
Copy link
Member

@vstinner vstinner left a 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)
Copy link
Member

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.

Copy link
Member

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;
Copy link
Member

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?

@vstinner
Copy link
Member

I created PR #111939 based on this PR: I changed the API and added tests.

@vstinner
Copy link
Member

I close this PR: #112028 was merged with a different API. Thanks @scoder, I wrote my PR based on yours ;-) And thanks for raising the need for such API.

@vstinner vstinner closed this Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-C-API type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants