Frozen BoxList instances cannot be pickled
评估
调研方向
Start with BoxList.__init__ and inspect how the frozen mutation guard is installed; the issue identifies the local function as the pickle failure. Reproduce with the pure-Python implementation, then check the Cython implementation as noted. Done means frozen instances round-trip with values and box_options intact and still reject mutations, while mutable lists remain mutable after round-tripping.
由索引模型根据 Issue 内容生成。
描述
A direct frozen BoxList cannot be pickled on develop (8364ce582dd4b4ff0d753e3efffa4b8675e809bc). The error occurs with every pickle protocol, including an empty list:
import pickle
from box import BoxList
value = BoxList([1, 2], frozen_box=True)
pickle.dumps(value)
# PicklingError / AttributeError:
# Can't pickle local object 'BoxList.__init__.<locals>.frozen'
BoxList.__init__ installs a local function on the instance to reject mutating methods. Pickle serializes those instance attributes, but cannot reference a locally defined function. The guard does not capture any local state, so using a module-level guard would make it serializable while retaining the same mutation errors after loading.
Expected: pickle round-trips preserve the values, box_options, and the existing frozen mutation guards. Ordinary mutable lists should continue to round-trip and remain mutable.
This is separate from #260 / PR #322 (nested Box options lost during unpickling) and #308 / PR #309 (nested Box subclass selection). PR #58 addressed older Python 3.7 pickling and outer-list freezing, but the local-function failure remains on current develop. No existing issue/PR for this specific failure was found in the full PR history or frozen/BoxList pickle searches.
Reproduced with the pure-Python implementation on CPython 3.14.6 / macOS. The Cython implementation also needs validation before submitting a fix. The contribution target is develop as specified in CONTRIBUTING.rst.
- 主要语言
- Python
- 星标
- 2.8k
- 派生
- 144
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
cdgriffith/Box 的其他 Issue
-
subclass of `Box` does not unpickle correctly可能已有人在做 @koriyoshi2041 于 157 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
cdgriffith/Box#308 ·
-
难度 3/5 1-2 天 新手友好度 42/100
cdgriffith/Box#307 · 1 条评论 ·
-
Dotted keys read from YAML are lost with box_dots / default_box可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 3/5 1-2 天 新手友好度 48/100
cdgriffith/Box#305 ·
-
[Bug] Camel killer box and box dots gives unexpected behaviour可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 3/5 1-2 天 新手友好度 30/100
cdgriffith/Box#300 ·
-
难度 3/5 1-2 天 新手友好度 42/100
cdgriffith/Box#298 ·
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
huggingface/smolagents#3106 ·
维护者通常 2 天内回复
-
area:scripts area:tests bug priority:later
难度 2/5 1-3 小时 新手友好度 72/100
Ikalus1988/MisakaNet#4358 ·
维护者通常 1 天内回复
-
Discovered ports from service discovery are never propagated to modules in Module.load()可能已有人在做 @vishalmore90 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
OWASP/Nettacker#1828 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
aws-samples/sample-per-model-bedrock#708 ·
维护者通常 1 天内回复
-
maintenance
难度 2/5 1-3 小时 新手友好度 62/100