Skip to content

C extension: pickling any FrozenList raises TypeError (atomic[bint] not convertible) #834

Description

@Mukller

Version: current master (frozenlist 1.8.1.dev0, commit after the free-threading changes)
Platform: Windows, CPython 3.13.7 — not platform-specific

Summary

Any FrozenList instance fails to pickle when the C extension is used:

import pickle
from frozenlist import FrozenList

fl = FrozenList([3, 1, 2])
fl.freeze()
pickle.dumps(fl)
TypeError: self._frozen cannot be converted to a Python object for pickling

The pure-Python implementation (FROZENLIST_NO_EXTENSIONS=1) round-trips fine on the same interpreter, so the two implementations have diverged.

Root cause

_frozenlist.pyx declares cdef atomic[bint] _frozen (added for free-threading support). Cython's auto-generated __reduce_cython__ cannot convert a libcpp.atomic.atomic[bint] member to a Python object, so pickling raises for every instance.

There is also no test coverage for pickling at all right now, which is why this went unnoticed.

Suggested fix

An explicit __reduce__ in the pyx class that serializes (items, frozen) through a small module-level constructor restores parity with the pure-Python implementation without giving up the atomic.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions