◐ Shell
clean mode source ↗

gh-111262: Make PyDict_Pop() public by scoder · Pull Request #111263 · python/cpython

@scoder

@scoder scoder commented

Oct 24, 2023

edited by github-actions Bot

Loading

@scoder

vstinner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change lacks tests.

.. versionadded:: 3.4


.. c:function:: PyObject* PyDict_Pop(PyObject *p, PyObject *key, PyObject *defaultobj)

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.

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?

pitrou

{
if (!PyDict_Check(dict)) {
PyErr_BadInternalCall();
return -1;

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

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

@vstinner

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.