Add `PyDict_AsFrozenDictAndClear` C-API
Open
@sobolevn is already working on this.
Since Jul 9, 2026.
interpreter-core
topic-C-API
type-feature
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Feature or enhancement
Discussion: https://discuss.python.org/t/provide-a-c-api-to-efficently-convert-dict-into-frozendict/107754/10
Looks like that all agree that this API would be useful.
How it works?
- We create a
dictby any existing C-API functions forPyDict_*. - Then we call
PyDict_AsFrozenDictAndClearwhich creates newfrozendictinstance from the existingdictwith O(1) complexity - It clears the initial
dictand it can be decrefed by the caller if needed
Linked PRs
- gh-153413
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.