8000 Fix some mypy errors by dstansby · Pull Request #3044 · zarr-developers/zarr-python · GitHub
[go: up one dir, main page]

Skip to content

Fix some mypy errors #3044

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

Merged
merged 5 commits into from
May 7, 2025
Merged
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
14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -348,27 +348,27 @@ python_version = "3.11"
ignore_missing_imports = true
namespace_packages = false


strict = true
warn_unreachable = true

enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]


[[tool.mypy.overrides]]
module = [
"zarr.v2.*",
"tests.package_with_entrypoint.*",
"tests.test_codecs.test_transpose",
"tests.test_config"
]
ignore_errors = true
strict = false

# TODO: Move the next modules up to the strict = false section
# and fix the errors
[[tool.mypy.overrides]]
module = [
"zarr.testing.stateful", # lots of hypothesis decorator errors
"tests.package_with_entrypoint.*",
"tests.test_codecs.test_codecs",
"tests.test_codecs.test_transpose",
"tests.test_metadata.*",
"tests.test_store.*",
"tests.test_config",
"tests.test_group",
"tests.test_indexing",
"tests.test_properties",
Expand Down
23 changes: 12 additions & 11 deletions tests/package_with_entrypoint/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from collections.abc import Iterable
from typing import Any

from numpy import ndarray
import numpy as np
import numpy.typing as npt

import zarr.core.buffer
from zarr.abc.codec import ArrayBytesCodec, CodecInput, CodecOutput, CodecPipeline
from zarr.abc.codec import ArrayBytesCodec, CodecInput, CodecPipeline
from zarr.codecs import BytesCodec
from zarr.core.array_spec import ArraySpec
from zarr.core.buffer import Buffer, NDBuffer
from zarr.core.common import BytesLike


class TestEntrypointCodec(ArrayBytesCodec):
Expand All @@ -16,14 +17,14 @@ class TestEntrypointCodec(ArrayBytesCodec):
async def encode(
self,
chunks_and_specs: Iterable[tuple[CodecInput | None, ArraySpec]],
) -> Iterable[CodecOutput | None]:
pass
) -> Iterable[Buffer | None]:
return [None]

async def decode(
self,
chunks_and_specs: Iterable[tuple[CodecInput | None, ArraySpec]],
) -> ndarray:
pass
) -> npt.NDArray[Any]:
return np.array(1)

def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
return input_byte_length
Expand All @@ -35,13 +36,13 @@ def __init__(self, batch_size: int = 1) -> None:

async def encode(
self, chunks_and_specs: Iterable[tuple[CodecInput | None, ArraySpec]]
) -> BytesLike:
pass
) -> Iterable[Buffer | None]:
return [None]

async def decode(
self, chunks_and_specs: Iterable[tuple[CodecInput | None, ArraySpec]]
) -> ndarray:
pass
) -> Iterable[NDBuffer | None]:
return np.array(1)


class TestEntrypointBuffer(Buffer):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_codecs/test_transpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async def test_transpose(
read_data = await _AsyncArrayProxy(a)[:, :].get()
assert np.array_equal(data, read_data)

assert isinstance(read_data, np.ndarray)
if runtime_read_order == "F":
assert read_data.flags["F_CONTIGUOUS"]
assert not read_data.flags["C_CONTIGUOUS"]
Expand Down Expand Up @@ -90,5 +91,5 @@ def test_transpose_invalid(
dtype=data.dtype,
fill_value=0,
chunk_key_encoding={"name": "v2", "separator": "."},
filters=[TransposeCodec(order=order)],
filters=[TransposeCodec(order=order)], # type: ignore[arg-type]
)
14 changes: 7 additions & 7 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import zarr
import zarr.api
from zarr import zeros
from zarr.abc.codec import CodecInput, CodecOutput, CodecPipeline
from zarr.abc.codec import CodecPipeline
from zarr.abc.store import ByteSetter, Store
from zarr.codecs import (
BloscCodec,
Expand All @@ -21,6 +21,7 @@
)
from zarr.core.array_spec import ArraySpec
from zarr.core.buffer import NDBuffer
from zarr.core.buffer.core import Buffer
from zarr.core.codec_pipeline import BatchedCodecPipeline
from zarr.core.config import BadConfigError, config
from zarr.core.indexing import SelectorTuple
Expand Down Expand Up @@ -144,7 +145,7 @@ def test_config_codec_pipeline_class(store: Store) -> None:
class MockCodecPipeline(BatchedCodecPipeline):
async def write(
self,
batch_info: Iterable[tuple[ByteSetter, ArraySpec, SelectorTuple, SelectorTuple]],
batch_info: Iterable[tuple[ByteSetter, ArraySpec, SelectorTuple, SelectorTuple, bool]],
value: NDBuffer,
drop_axes: tuple[int, ...] = (),
) -> None:
Expand Down Expand Up @@ -174,7 +175,7 @@ async def write(
class MockEnvCodecPipeline(CodecPipeline):
pass

register_pipeline(MockEnvCodecPipeline)
register_pipeline(MockEnvCodecPipeline) # type: ignore[type-abstract]

with mock.patch.dict(
os.environ, {"ZARR_CODEC_PIPELINE__PATH": fully_qualified_name(MockEnvCodecPipeline)}
Expand All @@ -191,10 +192,9 @@ def test_config_codec_implementation(store: Store) -> None:
_mock = Mock()

class MockBloscCodec(BloscCodec):
async def _encode_single(
self, chunk_data: CodecInput, chunk_spec: ArraySpec
) -> CodecOutput | None:
async def _encode_single(self, chunk_bytes: Buffer, chunk_spec: ArraySpec) -> Buffer | None:
_mock.call()
return None

register_codec("blosc", MockBloscCodec)
with config.set({"codecs.blosc": fully_qualified_name(MockBloscCodec)}):
Expand Down Expand Up @@ -245,7 +245,7 @@ def test_config_buffer_implementation() -> None:
# has default value
assert fully_qualified_name(get_buffer_class()) == config.defaults[0]["buffer"]

arr = zeros(shape=(100), store=StoreExpectingTestBuffer())
arr = zeros(shape=(100,), store=StoreExpectingTestBuffer())

# AssertionError of StoreExpectingTestBuffer when not using my buffer
with pytest.raises(AssertionError):
Expand Down
0