◐ Shell
clean mode source ↗

gh-145478: Implement `frozendict` into `functools.partial` by brijkapadia · Pull Request #145960 · python/cpython

@vstinner, do you know of more cases where it would be good to replace dict with frozendict with a deprecation period? Would it be worth it to create a helper for this?

How would you implement such deprecation period? In the documentation only?

There are many dictionaries in the stdlib which should not be modified but are declared as mutable dict (dict type). Changing these dictionaries to frozendict would be nice to make the API stricter. But I didn't propose such changes since it can affect projects expecting a mutable dictionary.

So far, if I recall correctly, only two changes (gh-144909 and gh-144910) were merged to replace dict with frozendict in private stdlib APIs. I was told that the _opcode_metadata change (private module) impacts Meta CinderX which does modify _opcode_metadata dictonaries on purpose (they wrote a simple change to become compatible with Python 3.15 frozendict).

There is also gh-144904 which replaced types.MappingProxyType with frozendict. It changed the dataclasses and email.headerregistry APIs in subtle way (return MappingProxyType instead of frozendict, it's documented).

Another example is gh-144906 which proposed converting errno.errorcode dict to a frozendict. The PR was rejected by the module maintainer, since it's useful to be able to modify errno.errorcode dictionary.

By the way, the SC decision includes:

Stdlib adoption should happen with each module maintainer’s approval, not as a mechanical sweep.