Skip to content

Apply Sourcery suggestions and fix typos #3131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/zarr/codecs/sharding.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ def validate(
)
if not isinstance(chunk_grid, RegularChunkGrid):
raise TypeError("Sharding is only compatible with regular chunk grids.")
if not all(
s % c == 0
if any(
s % c != 0
for s, c in zip(
chunk_grid.chunk_shape,
self.chunk_shape,
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ async def _create(
overwrite=overwrite,
)
else:
raise ValueError(f"Insupported zarr_format. Got: {zarr_format}")
raise ValueError(f"Unsupported zarr_format. Got: {zarr_format}")

if data is not None:
# insert user-provided data
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def parse_shapelike(data: int | Iterable[int]) -> tuple[int, ...]:
if not all(isinstance(v, int) for v in data_tuple):
msg = f"Expected an iterable of integers. Got {data} instead."
raise TypeError(msg)
if not all(v > -1 for v in data_tuple):
if any(v < 0 for v in data_tuple):
msg = f"Expected all values to be non-negative. Got {data} instead."
raise ValueError(msg)
return data_tuple
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/core/metadata/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ def parse_filters(data: object) -> tuple[numcodecs.abc.Codec, ...] | None:
"""
Parse a potential tuple of filters
"""
out: list[numcodecs.abc.Codec] = []

if data is None:
return data
if isinstance(data, Iterable):
out: list[numcodecs.abc.Codec] = []
for idx, val in enumerate(data):
if isinstance(val, numcodecs.abc.Codec):
out.append(val)
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/core/metadata/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def validate_codecs(codecs: tuple[Codec, ...], dtype: ZDType[TBaseDType, TBaseSc
# TODO: use codec ID instead of class name
codec_class_name = abc.__class__.__name__
# TODO: Fix typing here
if isinstance(dtype, VariableLengthUTF8) and not codec_class_name == "VLenUTF8Codec": # type: ignore[unreachable]
if isinstance(dtype, VariableLengthUTF8) and codec_class_name != "VLenUTF8Codec": # type: ignore[unreachable]
raise ValueError(
f"For string dtype, ArrayBytesCodec must be `VLenUTF8Codec`, got `{codec_class_name}`."
)
Expand Down
12 changes: 6 additions & 6 deletions src/zarr/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ def _parse_bytes_bytes_codec(data: dict[str, JSON] | Codec) -> BytesBytesCodec:
if not isinstance(result, BytesBytesCodec):
msg = f"Expected a dict representation of a BytesBytesCodec; got a dict representation of a {type(result)} instead."
raise TypeError(msg)
elif not isinstance(data, BytesBytesCodec):
raise TypeError(f"Expected a BytesBytesCodec. Got {type(data)} instead.")
else:
if not isinstance(data, BytesBytesCodec):
raise TypeError(f"Expected a BytesBytesCodec. Got {type(data)} instead.")
result = data
return result

Expand All @@ -210,9 +210,9 @@ def _parse_array_bytes_codec(data: dict[str, JSON] | Codec) -> ArrayBytesCodec:
if not isinstance(result, ArrayBytesCodec):
msg = f"Expected a dict representation of a ArrayBytesCodec; got a dict representation of a {type(result)} instead."
raise TypeError(msg)
elif not isinstance(data, ArrayBytesCodec):
raise TypeError(f"Expected a ArrayBytesCodec. Got {type(data)} instead.")
else:
if not isinstance(data, ArrayBytesCodec):
raise TypeError(f"Expected a ArrayBytesCodec. Got {type(data)} instead.")
result = data
return result

Expand All @@ -230,9 +230,9 @@ def _parse_array_array_codec(data: dict[str, JSON] | Codec) -> ArrayArrayCodec:
if not isinstance(result, ArrayArrayCodec):
msg = f"Expected a dict representation of a ArrayArrayCodec; got a dict representation of a {type(result)} instead."
raise TypeError(msg)
elif not isinstance(data, ArrayArrayCodec):
raise TypeError(f"Expected a ArrayArrayCodec. Got {type(data)} instead.")
else:
if not isinstance(data, ArrayArrayCodec):
raise TypeError(f"Expected a ArrayArrayCodec. Got {type(data)} instead.")
result = data
return result

Expand Down
4 changes: 2 additions & 2 deletions src/zarr/testing/stateful.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def delete_dir(self, data: DataObject) -> None:
# array_path = data.draw(st.sampled_from(self.all_arrays), label="Array move source")
# to_group = data.draw(st.sampled_from(self.all_groups), label="Array move destination")

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

# from_group_name = os.path.basename(from_group)
# assume(self.model.can_add(to_group, from_group_name))
# # fixme renaiming to self?
# # fixme renaming to self?
# new_path = f"{to_group}/{from_group_name}".lstrip("/")
# note(f"moving group '{from_group}' -> '{new_path}'")
# self.model.rename(from_group, new_path)
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async def store2(request: pytest.FixtureRequest, tmpdir: LEGACY_PATH) -> Store:
def sync_store(request: pytest.FixtureRequest, tmp_path: LEGACY_PATH) -> Store:
result = sync(parse_store(request.param, str(tmp_path)))
if not isinstance(result, Store):
raise TypeError("Wrong store class returned by test fixture! got " + result + " instead")
raise TypeError(f"Wrong store class returned by test fixture! got {result} instead")
return result


Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ async def test_open_falls_back_to_open_group_async(zarr_format: ZarrFormat) -> N
def test_open_modes_creates_group(tmp_path: pathlib.Path, mode: str) -> None:
# https://github.com/zarr-developers/zarr-python/issues/2490
zarr_dir = tmp_path / f"mode-{mode}-test.zarr"
if mode in ["r", "r+"]:
if mode in {"r", "r+"}:
# Expect FileNotFoundError to be raised if 'r' or 'r+' mode
with pytest.raises(FileNotFoundError):
zarr.open(store=zarr_dir, mode=mode)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_codec_entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def set_path() -> Generator[None, None, None]:
@pytest.mark.usefixtures("set_path")
@pytest.mark.parametrize("codec_name", ["TestEntrypointCodec", "TestEntrypointGroup.Codec"])
def test_entrypoint_codec(codec_name: str) -> None:
config.set({"codecs.test": "package_with_entrypoint." + codec_name})
config.set({"codecs.test": f"package_with_entrypoint.{codec_name}"})
cls_test = zarr.registry.get_codec_class("test")
assert cls_test.__qualname__ == codec_name

Expand All @@ -42,7 +42,7 @@ def test_entrypoint_pipeline() -> None:
def test_entrypoint_buffer(buffer_name: str) -> None:
config.set(
{
"buffer": "package_with_entrypoint." + buffer_name,
"buffer": f"package_with_entrypoint.{buffer_name}",
"ndbuffer": "package_with_entrypoint.TestEntrypointNDBuffer",
}
)
Expand Down
Loading