Skip to content

Commit 6b74fac

Browse files
Apply Sourcery suggestions and fix typos
1 parent 2911be8 commit 6b74fac

File tree

11 files changed

+17
-19
lines changed

11 files changed

+17
-19
lines changed

src/zarr/abc/metadata.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ def to_dict(self) -> dict[str, JSON]:
2828
value = getattr(self, key)
2929
if isinstance(value, Metadata):
3030
out_dict[field.name] = getattr(self, field.name).to_dict()
31-
elif isinstance(value, str):
32-
out_dict[key] = value
3331
elif isinstance(value, Sequence):
3432
out_dict[key] = tuple(v.to_dict() if isinstance(v, Metadata) else v for v in value)
3533
else:

src/zarr/core/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ async def _create(
660660
overwrite=overwrite,
661661
)
662662
else:
663-
raise ValueError(f"Insupported zarr_format. Got: {zarr_format}")
663+
raise ValueError(f"Unsupported zarr_format. Got: {zarr_format}")
664664

665665
if data is not None:
666666
# insert user-provided data

src/zarr/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def parse_shapelike(data: int | Iterable[int]) -> tuple[int, ...]:
152152
if not all(isinstance(v, int) for v in data_tuple):
153153
msg = f"Expected an iterable of integers. Got {data} instead."
154154
raise TypeError(msg)
155-
if not all(v > -1 for v in data_tuple):
155+
if any(v < 0 for v in data_tuple):
156156
msg = f"Expected all values to be non-negative. Got {data} instead."
157157
raise ValueError(msg)
158158
return data_tuple

src/zarr/core/indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def replace_ellipsis(selection: Any, shape: ChunkCoords) -> SelectionNormalized:
436436
selection = ensure_tuple(selection)
437437

438438
# count number of ellipsis present
439-
n_ellipsis = sum(1 for i in selection if i is Ellipsis)
439+
n_ellipsis = selection.count(Ellipsis)
440440

441441
if n_ellipsis > 1:
442442
# more than 1 is an error

src/zarr/core/metadata/v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ def parse_filters(data: object) -> tuple[numcodecs.abc.Codec, ...] | None:
266266
"""
267267
Parse a potential tuple of filters
268268
"""
269-
out: list[numcodecs.abc.Codec] = []
270269

271270
if data is None:
272271
return data
273272
if isinstance(data, Iterable):
273+
out: list[numcodecs.abc.Codec] = []
274274
for idx, val in enumerate(data):
275275
if isinstance(val, numcodecs.abc.Codec):
276276
out.append(val)

src/zarr/core/metadata/v3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def validate_codecs(codecs: tuple[Codec, ...], dtype: ZDType[TBaseDType, TBaseSc
9494
# TODO: use codec ID instead of class name
9595
codec_class_name = abc.__class__.__name__
9696
# TODO: Fix typing here
97-
if isinstance(dtype, VariableLengthUTF8) and not codec_class_name == "VLenUTF8Codec": # type: ignore[unreachable]
97+
if isinstance(dtype, VariableLengthUTF8) and codec_class_name != "VLenUTF8Codec": # type: ignore[unreachable]
9898
raise ValueError(
9999
f"For string dtype, ArrayBytesCodec must be `VLenUTF8Codec`, got `{codec_class_name}`."
100100
)

src/zarr/registry.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ def _parse_bytes_bytes_codec(data: dict[str, JSON] | Codec) -> BytesBytesCodec:
190190
if not isinstance(result, BytesBytesCodec):
191191
msg = f"Expected a dict representation of a BytesBytesCodec; got a dict representation of a {type(result)} instead."
192192
raise TypeError(msg)
193+
elif not isinstance(data, BytesBytesCodec):
194+
raise TypeError(f"Expected a BytesBytesCodec. Got {type(data)} instead.")
193195
else:
194-
if not isinstance(data, BytesBytesCodec):
195-
raise TypeError(f"Expected a BytesBytesCodec. Got {type(data)} instead.")
196196
result = data
197197
return result
198198

@@ -210,9 +210,9 @@ def _parse_array_bytes_codec(data: dict[str, JSON] | Codec) -> ArrayBytesCodec:
210210
if not isinstance(result, ArrayBytesCodec):
211211
msg = f"Expected a dict representation of a ArrayBytesCodec; got a dict representation of a {type(result)} instead."
212212
raise TypeError(msg)
213+
elif not isinstance(data, ArrayBytesCodec):
214+
raise TypeError(f"Expected a ArrayBytesCodec. Got {type(data)} instead.")
213215
else:
214-
if not isinstance(data, ArrayBytesCodec):
215-
raise TypeError(f"Expected a ArrayBytesCodec. Got {type(data)} instead.")
216216
result = data
217217
return result
218218

@@ -230,9 +230,9 @@ def _parse_array_array_codec(data: dict[str, JSON] | Codec) -> ArrayArrayCodec:
230230
if not isinstance(result, ArrayArrayCodec):
231231
msg = f"Expected a dict representation of a ArrayArrayCodec; got a dict representation of a {type(result)} instead."
232232
raise TypeError(msg)
233+
elif not isinstance(data, ArrayArrayCodec):
234+
raise TypeError(f"Expected a ArrayArrayCodec. Got {type(data)} instead.")
233235
else:
234-
if not isinstance(data, ArrayArrayCodec):
235-
raise TypeError(f"Expected a ArrayArrayCodec. Got {type(data)} instead.")
236236
result = data
237237
return result
238238

src/zarr/testing/stateful.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def delete_dir(self, data: DataObject) -> None:
248248
# array_path = data.draw(st.sampled_from(self.all_arrays), label="Array move source")
249249
# to_group = data.draw(st.sampled_from(self.all_groups), label="Array move destination")
250250

251-
# # fixme renaiming to self?
251+
# # fixme renaming to self?
252252
# array_name = os.path.basename(array_path)
253253
# assume(self.model.can_add(to_group, array_name))
254254
# new_path = f"{to_group}/{array_name}".lstrip("/")
@@ -265,7 +265,7 @@ def delete_dir(self, data: DataObject) -> None:
265265

266266
# from_group_name = os.path.basename(from_group)
267267
# assume(self.model.can_add(to_group, from_group_name))
268-
# # fixme renaiming to self?
268+
# # fixme renaming to self?
269269
# new_path = f"{to_group}/{from_group_name}".lstrip("/")
270270
# note(f"moving group '{from_group}' -> '{new_path}'")
271271
# self.model.rename(from_group, new_path)

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ async def store2(request: pytest.FixtureRequest, tmpdir: LEGACY_PATH) -> Store:
107107
def sync_store(request: pytest.FixtureRequest, tmp_path: LEGACY_PATH) -> Store:
108108
result = sync(parse_store(request.param, str(tmp_path)))
109109
if not isinstance(result, Store):
110-
raise TypeError("Wrong store class returned by test fixture! got " + result + " instead")
110+
raise TypeError(f"Wrong store class returned by test fixture! got {result} instead")
111111
return result
112112

113113

tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ async def test_open_falls_back_to_open_group_async(zarr_format: ZarrFormat) -> N
11741174
def test_open_modes_creates_group(tmp_path: pathlib.Path, mode: str) -> None:
11751175
# https://github.com/zarr-developers/zarr-python/issues/2490
11761176
zarr_dir = tmp_path / f"mode-{mode}-test.zarr"
1177-
if mode in ["r", "r+"]:
1177+
if mode in {"r", "r+"}:
11781178
# Expect FileNotFoundError to be raised if 'r' or 'r+' mode
11791179
with pytest.raises(FileNotFoundError):
11801180
zarr.open(store=zarr_dir, mode=mode)

tests/test_codec_entrypoints.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def set_path() -> Generator[None, None, None]:
2525
@pytest.mark.usefixtures("set_path")
2626
@pytest.mark.parametrize("codec_name", ["TestEntrypointCodec", "TestEntrypointGroup.Codec"])
2727
def test_entrypoint_codec(codec_name: str) -> None:
28-
config.set({"codecs.test": "package_with_entrypoint." + codec_name})
28+
config.set({"codecs.test": f"package_with_entrypoint.{codec_name}"})
2929
cls_test = zarr.registry.get_codec_class("test")
3030
assert cls_test.__qualname__ == codec_name
3131

@@ -42,7 +42,7 @@ def test_entrypoint_pipeline() -> None:
4242
def test_entrypoint_buffer(buffer_name: str) -> None:
4343
config.set(
4444
{
45-
"buffer": "package_with_entrypoint." + buffer_name,
45+
"buffer": f"package_with_entrypoint.{buffer_name}",
4646
"ndbuffer": "package_with_entrypoint.TestEntrypointNDBuffer",
4747
}
4848
)

0 commit comments

Comments
 (0)