Skip to content

Commit

Permalink
Apply assorted ruff/flake8-simplify rules (SIM) (#2259)
Browse files Browse the repository at this point in the history
* Apply ruff/flake8-simplify rule SIM103

SIM103 Return the condition directly

* Apply ruff/flake8-simplify rule SIM118

SIM118 Use `key in dict` instead of `key in dict.keys()`
  • Loading branch information
DimitriPapadopoulos authored Sep 26, 2024
1 parent f0443db commit 3365928
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/zarr/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ def is_scalar(value: Any, dtype: np.dtype[Any]) -> bool:
return True
if hasattr(value, "shape") and value.shape == ():
return True
if isinstance(value, tuple) and dtype.names and len(value) == len(dtype.names):
return True
return False
return isinstance(value, tuple) and dtype.names is not None and len(value) == len(dtype.names)


def is_pure_fancy_indexing(selection: Any, ndim: int) -> bool:
Expand Down
5 changes: 1 addition & 4 deletions src/zarr/store/zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ async def clear(self) -> None:

async def empty(self) -> bool:
with self._lock:
if self._zf.namelist():
return False
else:
return True
return not self._zf.namelist()

def __str__(self) -> str:
return f"zip://{self.path}"
Expand Down
4 changes: 2 additions & 2 deletions src/zarr/testing/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ async def test_list_prefix(self, store: S) -> None:
for prefix in prefixes:
observed = tuple(sorted(await _collect_aiterator(store.list_prefix(prefix))))
expected: tuple[str, ...] = ()
for key in store_dict.keys():
for key in store_dict:
if key.startswith(prefix):
expected += (key.removeprefix(prefix),)
expected = tuple(sorted(expected))
Expand All @@ -267,7 +267,7 @@ async def test_list_dir(self, store: S) -> None:
await store._set_many(store_dict.items())

keys_observed = await _collect_aiterator(store.list_dir(root))
keys_expected = {k.removeprefix(root + "/").split("/")[0] for k in store_dict.keys()}
keys_expected = {k.removeprefix(root + "/").split("/")[0] for k in store_dict}

assert sorted(keys_observed) == sorted(keys_expected)

Expand Down

0 comments on commit 3365928

Please sign in to comment.