python / python/cpython

frozendict cannot be pickled with protocols 0 and 1

未關閉
#155,324 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

extension-modules type-bug
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

首先比較 frozendict 的 getnewargs 與 frozenset 的 reduce 行為,以及協定 0 和 1 的 pickle.dumps 進入點。為兩種協定新增回歸測試涵蓋,並確認 frozendict 可以被序列化和還原,同時檢查現有的相關 PR gh-155325,了解已在進行的工作。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
backend
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。