Skip to content

Frozen BoxList instances cannot be pickled #344

Open

Description

@jihtsan

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions