python / python/cpython

Add `PyDict_AsFrozenDictAndClear` C-API

Open
#153,410 0 comments 0 reactions 1 assignee View on GitHub

@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?

  1. We create a dict by any existing C-API functions for PyDict_*.
  2. Then we call PyDict_AsFrozenDictAndClear which creates new frozendict instance from the existing dict with O(1) complexity
  3. It clears the initial dict and it can be decrefed by the caller if needed
Linked PRs
  • gh-153413

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.