zarr-python
zarr-python copied to clipboard
use __reduce__ for pickling instead of __setstate__ / __getstate__
In main, Array and Group have __setstate__ methods that directly call __init__, which isn't great (mypy complains about this). We can avoid calling __init__ by defining __reduce__ for these classes instead of __setstate__ / __getstate__.
Note that there are a lot of store classes that use __setstate__ / __getstate__ with direct calls of __init__. Clearing that up might be in scope for additional commits to this branch.
TODO:
- [ ] Add unit tests and/or doctests in docstrings
- [ ] Add docstrings and API docs for any new/modified user-facing classes and functions
- [ ] New/modified features documented in docs/tutorial.rst
- [ ] Changes documented in docs/release.rst
- [ ] GitHub Actions have all passed
- [ ] Test coverage is 100% (Codecov passes)
Codecov Report
Merging #1089 (2c6c779) into main (ece1810) will not change coverage. The diff coverage is
100.00%.
:exclamation: Current head 2c6c779 differs from pull request most recent head 364d793. Consider uploading reports for the commit 364d793 to get more accurate results
@@ Coverage Diff @@
## main #1089 +/- ##
=======================================
Coverage 99.94% 99.94%
=======================================
Files 34 34
Lines 13846 13844 -2
=======================================
- Hits 13839 13837 -2
Misses 7 7
| Impacted Files | Coverage Δ | |
|---|---|---|
| zarr/core.py | 100.00% <100.00%> (ø) |
|
| zarr/hierarchy.py | 99.78% <100.00%> (-0.01%) |
:arrow_down: |
Things are green and reading https://docs.python.org/3/library/pickle.html#object.reduce this seems to follow sensibly, but open to other opinions.
@d-v-b: can you coordinate the entries you want for docs/release.rst for this?