From 8c4bc6eea03fa8a307f2eef9f8f7142c9dd5793e Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 26 Feb 2025 20:53:22 +0100 Subject: [PATCH 1/5] Enforce ruff/Pylint rules (PLE, PLR) --- pyproject.toml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index b4783b5be3..18b3a37979 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -319,6 +319,8 @@ extend-select = [ "PERF", # Perflint "PIE", # flake8-pie "PGH", # pygrep-hooks + "PLE", # Pylint Error + "PLR", # Pylint Refactor "PT", # flake8-pytest-style "PYI", # flake8-pyi "RET", # flake8-return @@ -333,6 +335,15 @@ extend-select = [ ] ignore = [ "ANN401", + "PLR0124", + "PLR0904", + "PLR0911", + "PLR0912", + "PLR0913", + "PLR0914", + "PLR0915", + "PLR0917", + "PLR2004", "PT011", # TODO: apply this rule "RET505", "RET506", From 438f3792b2261735c4a9f450954e076bbd4a6f36 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 26 Feb 2025 20:54:07 +0100 Subject: [PATCH 2/5] Apply ruff/Pylint rule PLR5501 PLR5501 Use `elif` instead of `else` then `if`, to reduce indentation --- src/zarr/core/codec_pipeline.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/zarr/core/codec_pipeline.py b/src/zarr/core/codec_pipeline.py index 4cecc3a6d1..21381594ae 100644 --- a/src/zarr/core/codec_pipeline.py +++ b/src/zarr/core/codec_pipeline.py @@ -529,13 +529,12 @@ async def _read_key( ): if chunk_array is None: chunk_array_batch.append(None) # type: ignore[unreachable] + elif not chunk_spec.config.write_empty_chunks and chunk_array.all_equal( + fill_value_or_default(chunk_spec) + ): + chunk_array_batch.append(None) else: - if not chunk_spec.config.write_empty_chunks and chunk_array.all_equal( - fill_value_or_default(chunk_spec) - ): - chunk_array_batch.append(None) - else: - chunk_array_batch.append(chunk_array) + chunk_array_batch.append(chunk_array) chunk_bytes_batch = await self.encode_batch( [ From fcf7ee7127e855dc6343456f88c6ab3cd8c4676f Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 26 Feb 2025 20:55:16 +0100 Subject: [PATCH 3/5] Apply ruff/Pytlint rule PLR6104 PLR6104 Use `|=` to perform an augmented assignment directly --- src/zarr/core/group.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zarr/core/group.py b/src/zarr/core/group.py index b810041e7b..909f2e4f42 100644 --- a/src/zarr/core/group.py +++ b/src/zarr/core/group.py @@ -3450,7 +3450,7 @@ def _parse_hierarchy_dict( # but not if an empty dict was provided, because any empty hierarchy has no nodes if len(data_normed_keys) > 0 and "" not in data_normed_keys: z_format = next(iter(data_normed_keys.values())).zarr_format - data_normed_keys = data_normed_keys | {"": ImplicitGroupMarker(zarr_format=z_format)} + data_normed_keys |= {"": ImplicitGroupMarker(zarr_format=z_format)} out: dict[str, GroupMetadata | ArrayV2Metadata | ArrayV3Metadata] = {**data_normed_keys} From d9e1072d35c8f9c5d469c44fe7951c112e26ffa9 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 26 Feb 2025 20:57:15 +0100 Subject: [PATCH 4/5] Apply ruff preview rule RUF036 RUF036 `None` not at the end of the type annotation. --- src/zarr/core/array.py | 2 +- src/zarr/core/chunk_grids.py | 2 +- src/zarr/testing/strategies.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/zarr/core/array.py b/src/zarr/core/array.py index f0cd5dd734..99c8ed9307 100644 --- a/src/zarr/core/array.py +++ b/src/zarr/core/array.py @@ -2119,7 +2119,7 @@ def filters(self) -> tuple[Numcodec, ...] | tuple[ArrayArrayCodec, ...]: return self.async_array.filters @property - def serializer(self) -> None | ArrayBytesCodec: + def serializer(self) -> ArrayBytesCodec | None: """ Array-to-bytes codec to use for serializing the chunks into bytes. """ diff --git a/src/zarr/core/chunk_grids.py b/src/zarr/core/chunk_grids.py index 3d7313cd5d..3129f9b9e9 100644 --- a/src/zarr/core/chunk_grids.py +++ b/src/zarr/core/chunk_grids.py @@ -743,7 +743,7 @@ def _auto_partition( given the dtype and shard shape. Otherwise, the chunks will be returned as-is. """ if shard_shape is None: - _shards_out: None | tuple[int, ...] = None + _shards_out: tuple[int, ...] | None = None if chunk_shape == "auto": _chunks_out = _guess_chunks(array_shape, item_size) else: diff --git a/src/zarr/testing/strategies.py b/src/zarr/testing/strategies.py index e382235e0e..aacfbd8cd6 100644 --- a/src/zarr/testing/strategies.py +++ b/src/zarr/testing/strategies.py @@ -124,7 +124,7 @@ def clear_store(x: Store) -> Store: @st.composite -def dimension_names(draw: st.DrawFn, *, ndim: int | None = None) -> list[None | str] | None: +def dimension_names(draw: st.DrawFn, *, ndim: int | None = None) -> list[str | None] | None: simple_text = st.text(zarr_key_chars, min_size=0) return draw(st.none() | st.lists(st.none() | simple_text, min_size=ndim, max_size=ndim)) # type: ignore[arg-type] From c383d7d23e7c3b6be69dc16dc2bc1eabaf6a74b2 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 19 Jun 2025 13:24:31 +0200 Subject: [PATCH 5/5] Apply ruff/Pylint preview rule PLR6104 PLR6104 Use `-=` to perform an augmented assignment directly --- src/zarr/testing/stateful.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/zarr/testing/stateful.py b/src/zarr/testing/stateful.py index d6c43f4ecc..3adb272132 100644 --- a/src/zarr/testing/stateful.py +++ b/src/zarr/testing/stateful.py @@ -308,8 +308,8 @@ def delete_dir(self, data: DataObject) -> None: for node in self.all_groups | self.all_arrays: if node.startswith(path): matches.add(node) - self.all_groups = self.all_groups - matches - self.all_arrays = self.all_arrays - matches + self.all_groups -= matches + self.all_arrays -= matches # @precondition(lambda self: bool(self.all_groups)) # @precondition(lambda self: bool(self.all_arrays))