frozendict cannot be pickled with protocols 0 and 1
Open
Nobody has claimed this yet.
extension-modules
type-bug
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
frozendict cannot be pickled with protocols 0 and 1, while frozenset can:
>>> import pickle
>>> pickle.dumps(frozendict(a=1), 0)
Traceback (most recent call last):
...
TypeError: cannot pickle 'frozendict' object
>>> pickle.dumps(frozenset({1}), 0) # works
Protocols 2 through 5 already work. frozendict only defines __getnewargs__,
a protocol-2-and-later mechanism, while frozenset defines __reduce__, which
works at every protocol.
CPython versions tested on:
3.16 (main)
Operating systems tested on:
Linux, macOS
Linked PRs
- gh-155325
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.
Research direction
Start by comparing frozendict's getnewargs with frozenset's reduce behavior and the pickle.dumps entry point for protocols 0 and 1. Add regression coverage for both protocols and confirm that frozendict can be serialized and restored, while checking the existing linked PR gh-155325 for work already underway.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100