From 5f0f62ad96808b795fb2ba3ec3e059aca8340a06 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 25 Sep 2024 08:38:06 +0200 Subject: [PATCH 1/3] Apply ruff/flake8-return rule RET501 RET501 Do not explicitly `return None` in function if it is the only possible return value --- src/zarr/abc/store.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zarr/abc/store.py b/src/zarr/abc/store.py index 2f02ac36ad..c453733f00 100644 --- a/src/zarr/abc/store.py +++ b/src/zarr/abc/store.py @@ -170,7 +170,7 @@ async def _set_many(self, values: Iterable[tuple[str, Buffer]]) -> None: Insert multiple (key, value) pairs into storage. """ await gather(*(self.set(key, value) for key, value in values)) - return None + return @property @abstractmethod From fc8f9f11d7ea002367873b7258f549fa01181741 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 25 Sep 2024 08:39:16 +0200 Subject: [PATCH 2/3] Apply ruff/flake8-return rule RET504 RET504 Unnecessary assignment before `return` statement --- src/zarr/core/buffer/core.py | 3 +-- tests/v3/conftest.py | 6 ++---- tests/v3/test_store/test_stateful_store.py | 8 ++------ 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/zarr/core/buffer/core.py b/src/zarr/core/buffer/core.py index 0a56db5e74..49f04aafa0 100644 --- a/src/zarr/core/buffer/core.py +++ b/src/zarr/core/buffer/core.py @@ -469,10 +469,9 @@ def all_equal(self, other: Any, equal_nan: bool = True) -> bool: return False # use array_equal to obtain equal_nan=True functionality data, other = np.broadcast_arrays(self._data, other) - result = np.array_equal( + return np.array_equal( self._data, other, equal_nan=equal_nan if self._data.dtype.kind not in "US" else False ) - return result def fill(self, value: Any) -> None: self._data.fill(value) diff --git a/tests/v3/conftest.py b/tests/v3/conftest.py index c3516f676c..4a2ef26433 100644 --- a/tests/v3/conftest.py +++ b/tests/v3/conftest.py @@ -46,8 +46,7 @@ def path_type(request: pytest.FixtureRequest) -> Any: @pytest.fixture async def store_path(tmpdir: LEGACY_PATH) -> StorePath: store = await LocalStore.open(str(tmpdir), mode="w") - p = StorePath(store) - return p + return StorePath(store) @pytest.fixture(scope="function") @@ -88,13 +87,12 @@ async def async_group(request: pytest.FixtureRequest, tmpdir: LEGACY_PATH) -> As param: AsyncGroupRequest = request.param store = await parse_store(param.store, str(tmpdir)) - agroup = await AsyncGroup.from_store( + return await AsyncGroup.from_store( store, attributes=param.attributes, zarr_format=param.zarr_format, exists_ok=False, ) - return agroup @pytest.fixture(params=["numpy", "cupy"]) diff --git a/tests/v3/test_store/test_stateful_store.py b/tests/v3/test_store/test_stateful_store.py index 85a31f9eb3..057d1a9501 100644 --- a/tests/v3/test_store/test_stateful_store.py +++ b/tests/v3/test_store/test_stateful_store.py @@ -40,16 +40,12 @@ def list(self) -> list: return self._sync_iter(self.store.list()) def get(self, key: str, prototype: BufferPrototype) -> zarr.core.buffer.Buffer: - obs = self._sync(self.store.get(key, prototype=prototype)) - return obs + return self._sync(self.store.get(key, prototype=prototype)) def get_partial_values( self, key_ranges: list, prototype: BufferPrototype ) -> zarr.core.buffer.Buffer: - obs_partial = self._sync( - self.store.get_partial_values(prototype=prototype, key_ranges=key_ranges) - ) - return obs_partial + return self._sync(self.store.get_partial_values(prototype=prototype, key_ranges=key_ranges)) def delete(self, path: str) -> None: return self._sync(self.store.delete(path)) From c157bb70bdb201fb595451d4279781ebc26d0f04 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 25 Sep 2024 08:41:52 +0200 Subject: [PATCH 3/3] Enforce ruff/flake8-return rules (RET) --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index ed6c25893c..7f2e1dfbf2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -213,6 +213,7 @@ extend-select = [ "PGH", # pygrep-hooks "PYI", # flake8-pyi "RSE", # flake8-raise + "RET", # flake8-return "RUF", "TCH", # flake8-type-checking "TRY", # tryceratops @@ -220,6 +221,8 @@ extend-select = [ ] ignore = [ "PYI013", + "RET505", + "RET506", "RUF005", "TRY003", # https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules