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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ repos:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format
- repo: https://github.com/sourcery-ai/sourcery
rev: v1.37.0
hooks:
- id: sourcery
args: [--diff=git diff HEAD, --no-summary]
- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
hooks:
Expand Down
82 changes: 82 additions & 0 deletions .sourcery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# 🪄 This is your project's Sourcery configuration file.

# You can use it to get Sourcery working in the way you want, such as
# ignoring specific refactorings, skipping directories in your project,
# or writing custom rules.

# 📚 For a complete reference to this file, see the documentation at
# https://docs.sourcery.ai/Configuration/Project-Settings/

# This file was auto-generated by Sourcery on 2025-06-20 at 14:38.

version: '1' # The schema version of this config file

ignore: # A list of paths or files which Sourcery will ignore.
- .git
- env
- .env
- .tox
- node_modules
- vendor
- venv
- .venv
- ~/.pyenv
- ~/.rye
- ~/.vscode
- .vscode
- ~/.cache
- ~/.config
- ~/.local

rule_settings:
enable:
- default
disable: [] # A list of rule IDs Sourcery will never suggest.
rule_types:
- refactoring
- suggestion
- comment
python_version: '3.11' # A string specifying the lowest Python version your project supports. Sourcery will not suggest refactorings requiring a higher Python version.

# rules: # A list of custom rules Sourcery will include in its analysis.
# - id: no-print-statements
# description: Do not use print statements in the test directory.
# pattern: print(...)
# language: python
# replacement:
# condition:
# explanation:
# paths:
# include:
# - test
# exclude:
# - conftest.py
# tests: []
# tags: []

# rule_tags: {} # Additional rule tags.

# metrics:
# quality_threshold: 25.0

# github:
# labels: []
# ignore_labels:
# - sourcery-ignore
# request_review: author
# sourcery_branch: sourcery/{base_branch}

# clone_detection:
# min_lines: 3
# min_duplicates: 2
# identical_clones_only: false

# proxy:
# url:
# ssl_certs_file:
# no_ssl_verify: false

# coding_assistant:
# project_description: ''
# enabled: true
# recipe_prompts: {}
2 changes: 1 addition & 1 deletion src/zarr/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@
overwrite=overwrite,
)
else:
raise ValueError(f"Insupported zarr_format. Got: {zarr_format}")
raise ValueError(f"Unsupported zarr_format. Got: {zarr_format}")

Check warning on line 663 in src/zarr/core/array.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/core/array.py#L663

Added line #L663 was not covered by tests

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 @@ -152,7 +152,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 @@
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.")

Check warning on line 194 in src/zarr/registry.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/registry.py#L194

Added line #L194 was not covered by tests
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 @@
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.")

Check warning on line 214 in src/zarr/registry.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/registry.py#L214

Added line #L214 was not covered by tests
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 @@
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.")

Check warning on line 234 in src/zarr/registry.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/registry.py#L234

Added line #L234 was not covered by tests
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 @@ -248,7 +248,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 @@ -265,7 +265,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 @@ -1174,7 +1174,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