Skip to content

Commit 3365928

Browse files
Apply assorted ruff/flake8-simplify rules (SIM) (zarr-developers#2259)
* 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()`
1 parent f0443db commit 3365928

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

src/zarr/core/indexing.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,7 @@ def is_scalar(value: Any, dtype: np.dtype[Any]) -> bool:
218218
return True
219219
if hasattr(value, "shape") and value.shape == ():
220220
return True
221-
if isinstance(value, tuple) and dtype.names and len(value) == len(dtype.names):
222-
return True
223-
return False
221+
return isinstance(value, tuple) and dtype.names is not None and len(value) == len(dtype.names)
224222

225223

226224
def is_pure_fancy_indexing(selection: Any, ndim: int) -> bool:

src/zarr/store/zip.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,7 @@ async def clear(self) -> None:
110110

111111
async def empty(self) -> bool:
112112
with self._lock:
113-
if self._zf.namelist():
114-
return False
115-
else:
116-
return True
113+
return not self._zf.namelist()
117114

118115
def __str__(self) -> str:
119116
return f"zip://{self.path}"

src/zarr/testing/store.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ async def test_list_prefix(self, store: S) -> None:
248248
for prefix in prefixes:
249249
observed = tuple(sorted(await _collect_aiterator(store.list_prefix(prefix))))
250250
expected: tuple[str, ...] = ()
251-
for key in store_dict.keys():
251+
for key in store_dict:
252252
if key.startswith(prefix):
253253
expected += (key.removeprefix(prefix),)
254254
expected = tuple(sorted(expected))
@@ -267,7 +267,7 @@ async def test_list_dir(self, store: S) -> None:
267267
await store._set_many(store_dict.items())
268268

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

272272
assert sorted(keys_observed) == sorted(keys_expected)
273273

0 commit comments

Comments
 (0)