Frozen BoxList instances cannot be pickled

未关闭
#344 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@Fire162 已经在做这个了。

开始于 2026年10月29日。

  • #345 来自 @Fire162 —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
76/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

cdgriffith/Box 的其他 Issue

查看 cdgriffith/Box 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。