PEP 839: PyFrozenSetWriter and PyFrozenDictWriter C API
The Python C API introduces PyFrozenSetWriter and PyFrozenDictWriter to facilitate the creation of immutable collections. These builders allow for the construction of frozenset and frozendict objects in a single pass without intermediate mutable states.
Verified State Diff
Impact & Verification Analysis
CPython core developers, extension module authors, and performance-critical library maintainers.
Improves memory efficiency and performance for immutable data structure creation while enforcing stricter object immutability patterns at the C level.
Full Fact Overview
PEP 839 extends the builder pattern established by PEP 782 (PyBytesWriter) to the Python C API for immutable types. By utilizing these new writer interfaces, developers can populate collections directly into their final immutable form. This architectural shift eliminates the overhead and potential safety risks associated with creating a mutable intermediate object (like a standard dict or set) before converting it to its frozen counterpart, aligning with the upcoming introduction of frozendict as defined in PEP 814.