From 02087e999cad3485ec9bd9a26eb289575e3e304c Mon Sep 17 00:00:00 2001 From: NIK-TIGER-BILL Date: Wed, 3 Jun 2026 23:08:52 +0000 Subject: [PATCH] fix(storage): remove VerboseModule to make zarr.storage picklable The VerboseModule subclass prevented from being serialized by cloudpickle (and therefore Dask). The only purpose of the subclass was to emit a deprecation warning when setting , which has been deprecated for a long time. Closes #4029 Signed-off-by: NIK-TIGER-BILL --- src/zarr/storage/__init__.py | 20 -------------------- tests/test_v2.py | 13 +++++++++++-- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/zarr/storage/__init__.py b/src/zarr/storage/__init__.py index 00df50214f..645d802155 100644 --- a/src/zarr/storage/__init__.py +++ b/src/zarr/storage/__init__.py @@ -1,9 +1,3 @@ -import sys -import warnings -from types import ModuleType -from typing import Any - -from zarr.errors import ZarrDeprecationWarning from zarr.storage._common import StoreLike, StorePath from zarr.storage._fsspec import FsspecStore from zarr.storage._local import LocalStore @@ -27,18 +21,4 @@ ] -class VerboseModule(ModuleType): - def __setattr__(self, attr: str, value: Any) -> None: - if attr == "default_compressor": - warnings.warn( - "setting zarr.storage.default_compressor is deprecated, use " - "zarr.config to configure array.v2_default_compressor " - "e.g. config.set({'codecs.zstd':'numcodecs.Zstd', 'array.v2_default_compressor.numeric': 'zstd'})", - ZarrDeprecationWarning, - stacklevel=1, - ) - else: - super().__setattr__(attr, value) - -sys.modules[__name__].__class__ = VerboseModule diff --git a/tests/test_v2.py b/tests/test_v2.py index cb990f6159..b478c9143c 100644 --- a/tests/test_v2.py +++ b/tests/test_v2.py @@ -224,9 +224,18 @@ def test_v2_non_contiguous(numpy_order: Literal["C", "F"], zarr_order: Literal[" assert (sub_arr).flags.c_contiguous -def test_default_compressor_deprecation_warning() -> None: - with pytest.warns(ZarrDeprecationWarning, match="default_compressor is deprecated"): +def test_storage_module_is_picklable() -> None: + import pickle + + # regression test for gh-4029 + assert pickle.dumps(zarr.storage) + + +def test_default_compressor_no_longer_warns() -> None: + # VerboseModule removed in gh-4029 to make zarr.storage picklable + with pytest.warns() as record: zarr.storage.default_compressor = "zarr.codecs.zstd.ZstdCodec()" # type: ignore[attr-defined] + assert not any("default_compressor is deprecated" in str(w.message) for w in record) @pytest.mark.parametrize("fill_value", [None, (b"", 0, 0.0)], ids=["no_fill", "fill"])