Skip to content

Conversation

@neriat
Copy link

@neriat neriat commented Dec 23, 2025

Pickle support was removed in v0.25.0 when upgrading to pyo3 0.23 due to breaking API changes in the old __reduce__ implementation.

This PR restores pickle support using the __getnewargs__ protocol, which is simpler and more idiomatic for immutable byte-wrapper types. This approach is fully compatible with pyo3 0.23+ and avoids deprecated APIs like IntoPy and Python::acquire_gil().

Changes

  • Add __getnewargs__ method to Pubkey, Hash, and Signature
  • Re-add pickle tests for all three types
  • All 35 existing tests pass ✅

Implementation Details

The implementation leverages the immutable nature of these types (glorified byte wrappers), returning their byte representation directly to pickle for reconstruction via __new__. This is much simpler than the old __reduce__ approach and doesn't require any manual class lookup or deprecated pyo3 APIs.

Testing

uv run pytest tests/test_pubkey.py::test_pickle tests/test_hash.py::test_pickle tests/test_signature.py::test_pickle -v
# All tests PASSED

@neriat neriat force-pushed the re-add-pickle-support branch from ddb14ff to 93d4290 Compare December 23, 2025 15:37
Pickle support was removed in v0.25.0 when upgrading to pyo3 0.23
due to breaking API changes in the old __reduce__ implementation.

This commit restores pickle support using the __getnewargs__ protocol,
which is simpler and more idiomatic for immutable byte-wrapper types.
This approach is fully compatible with pyo3 0.23+ and avoids deprecated
APIs like IntoPy and Python::acquire_gil().

Changes:
- Add __getnewargs__ method to Pubkey, Hash, and Signature
- Re-add pickle tests for all three types
- All 35 existing tests pass

The implementation leverages the immutable nature of these types,
returning their byte representation directly to pickle for
reconstruction via __new__.
@neriat neriat force-pushed the re-add-pickle-support branch from 93d4290 to dd8db6a Compare December 23, 2025 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant