FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

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

/ cpython Public

gh-111262: Make PyDict_Pop() public - #111263

Closed
scoder wants to merge 1 commit into
python:mainfrom
scoder:py313_pydict_capi
Closed

gh-111262: Make PyDict_Pop() public#111263
scoder wants to merge 1 commit into
python:mainfrom
scoder:py313_pydict_capi

Conversation

scoder commented Oct 24, 2023
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Contributor

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 commented Oct 24, 2023

Copy link
Copy Markdown
Contributor Author

@vstinner

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

vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The change lacks tests.

Comment thread Doc/c-api/dict.rst
.. versionadded:: 3.4


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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I would prefer to return -1 on error, 0 if the key doesn't exist, 1 if the key exists.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

How would the caller know the popped value then?

Comment thread Objects/dictobject.c
{
if (!PyDict_Check(dict)) {
PyErr_BadInternalCall();
return -1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Should certainly be return NULL?

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
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 closed this Nov 14, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

4 participants


Back | FazBrowse Home | New Git URL