Skip to content

gh-153410: Add PyDict_AsFrozenDictAndClear C-API#153413

Open
sobolevn wants to merge 9 commits into
python:mainfrom
sobolevn:issue-153410
Open

gh-153410: Add PyDict_AsFrozenDictAndClear C-API#153413
sobolevn wants to merge 9 commits into
python:mainfrom
sobolevn:issue-153410

Conversation

@sobolevn

@sobolevn sobolevn commented Jul 9, 2026

Copy link
Copy Markdown
Member

@read-the-docs-community

read-the-docs-community Bot commented Jul 9, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33514449 | 📁 Comparing 3133dd1 against main (cd9994e)

  🔍 Preview build  

3 files changed
± c-api/dict.html
± whatsnew/3.16.html
± whatsnew/changelog.html

Comment thread Doc/c-api/dict.rst Outdated
Comment thread Doc/c-api/dict.rst Outdated
Comment thread Lib/test/test_capi/test_dict.py Outdated
Comment thread Lib/test/test_capi/test_dict.py Outdated
sobolevn and others added 2 commits July 9, 2026 14:33
Co-authored-by: Victor Stinner <vstinner@python.org>
Comment thread Lib/test/test_capi/test_dict.py Outdated
Comment thread Objects/dictobject.c Outdated
Comment thread Objects/dictobject.c
Comment thread Objects/dictobject.c Outdated
Comment thread Lib/test/test_capi/test_dict.py
Comment thread Lib/test/test_capi/test_dict.py

@vstinner 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.

LGTM.

You should now open an issue in https://github.com/capi-workgroup/decisions/issues/ to ask the C API Working Group to validate the API.

Comment thread Doc/c-api/dict.rst Outdated
Comment thread Objects/dictobject.c
PyDictKeysObject *keys = old->ma_keys;
PyDictValues *values = old->ma_values;

// Clear the old dict keys and values, but do not decref them:

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.

By the way, the existing similar (but private) _PyList_AsTupleAndClear() has a similar design: first make the list empty, and then create a tuple from the list items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants