python / python/cpython

frozendict cannot be pickled with protocols 0 and 1

Open
#155,324 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

extension-modules type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
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

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.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.