diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 58cbac3c45..578a66fd07 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -31,3 +31,5 @@ repos: - types-setuptools - pytest - numpy + - numcodecs + - zstandard diff --git a/pyproject.toml b/pyproject.toml index 4bcbfd0a0a..616c388f99 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -187,21 +187,7 @@ python_version = "3.10" ignore_missing_imports = true namespace_packages = false -warn_unused_configs = true -warn_redundant_casts = true -warn_unused_ignores = true -strict_equality = true -strict_concatenate = true - -check_untyped_defs = true -disallow_untyped_decorators = true -disallow_any_generics = true - -disallow_incomplete_defs = true -disallow_untyped_calls = true - -disallow_untyped_defs = true -no_implicit_reexport = true +strict = true [[tool.mypy.overrides]] @@ -238,6 +224,13 @@ module = [ disallow_untyped_defs = false +[[tool.mypy.overrides]] +module = [ + "zarr.metadata", + "zarr.store.remote" +] +warn_return_any = false + [tool.pytest.ini_options] minversion = "7" testpaths = ["tests"] diff --git a/src/zarr/codecs/sharding.py b/src/zarr/codecs/sharding.py index ec5306ee80..cea788840d 100644 --- a/src/zarr/codecs/sharding.py +++ b/src/zarr/codecs/sharding.py @@ -101,7 +101,7 @@ def is_all_empty(self) -> bool: return bool(np.array_equiv(self.offsets_and_lengths, MAX_UINT_64)) def get_full_chunk_map(self) -> npt.NDArray[np.bool_]: - return self.offsets_and_lengths[..., 0] != MAX_UINT_64 + return np.not_equal(self.offsets_and_lengths[..., 0], MAX_UINT_64) def get_chunk_slice(self, chunk_coords: ChunkCoords) -> tuple[int, int] | None: localized_chunk = self._localize_chunk(chunk_coords) diff --git a/src/zarr/codecs/zstd.py b/src/zarr/codecs/zstd.py index 76e625ad6a..451fae8b37 100644 --- a/src/zarr/codecs/zstd.py +++ b/src/zarr/codecs/zstd.py @@ -55,11 +55,11 @@ def to_dict(self) -> dict[str, JSON]: def _compress(self, data: npt.NDArray[Any]) -> bytes: ctx = ZstdCompressor(level=self.level, write_checksum=self.checksum) - return ctx.compress(data) + return ctx.compress(data.tobytes()) def _decompress(self, data: npt.NDArray[Any]) -> bytes: ctx = ZstdDecompressor() - return ctx.decompress(data) + return ctx.decompress(data.tobytes()) async def _decode_single( self, diff --git a/src/zarr/common.py b/src/zarr/common.py index 9527efbbce..ec5d870f92 100644 --- a/src/zarr/common.py +++ b/src/zarr/common.py @@ -7,7 +7,15 @@ from collections.abc import Iterable from dataclasses import dataclass from enum import Enum -from typing import TYPE_CHECKING, Any, Literal, ParamSpec, TypeVar, overload +from typing import ( + TYPE_CHECKING, + Any, + Literal, + ParamSpec, + TypeVar, + cast, + overload, +) if TYPE_CHECKING: from collections.abc import Awaitable, Callable, Iterator @@ -178,5 +186,5 @@ def parse_fill_value(data: Any) -> Any: def parse_order(data: Any) -> Literal["C", "F"]: if data in ("C", "F"): - return data + return cast(Literal["C", "F"], data) raise ValueError(f"Expected one of ('C', 'F'), got {data} instead.") diff --git a/src/zarr/config.py b/src/zarr/config.py index 5b1640bd56..7c5b48a16c 100644 --- a/src/zarr/config.py +++ b/src/zarr/config.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any, Literal +from typing import Any, Literal, cast from donfig import Config @@ -18,6 +18,6 @@ def parse_indexing_order(data: Any) -> Literal["C", "F"]: if data in ("C", "F"): - return data + return cast(Literal["C", "F"], data) msg = f"Expected one of ('C', 'F'), got {data} instead." raise ValueError(msg) diff --git a/src/zarr/group.py b/src/zarr/group.py index 4ff2176fd9..2401934b84 100644 --- a/src/zarr/group.py +++ b/src/zarr/group.py @@ -5,7 +5,7 @@ import logging from collections.abc import Iterator from dataclasses import asdict, dataclass, field, replace -from typing import TYPE_CHECKING, overload +from typing import TYPE_CHECKING, Literal, cast, overload import numpy.typing as npt @@ -37,7 +37,7 @@ def parse_zarr_format(data: Any) -> ZarrFormat: if data in (2, 3): - return data + return cast(Literal[2, 3], data) msg = msg = f"Invalid zarr_format. Expected one 2 or 3. Got {data}." raise ValueError(msg) diff --git a/src/zarr/v2/n5.py b/src/zarr/v2/n5.py index 4ea5e45721..a6fd39f5b8 100644 --- a/src/zarr/v2/n5.py +++ b/src/zarr/v2/n5.py @@ -780,7 +780,7 @@ def compressor_config_to_zarr(compressor_config: Dict[str, Any]) -> Optional[Dic return zarr_config -class N5ChunkWrapper(Codec): +class N5ChunkWrapper(Codec): # type: ignore[misc] codec_id = "n5_wrapper" def __init__(self, dtype, chunk_shape, compressor_config=None, compressor=None): diff --git a/src/zarr/v2/util.py b/src/zarr/v2/util.py index 48d7d30d88..6926bb2d14 100644 --- a/src/zarr/v2/util.py +++ b/src/zarr/v2/util.py @@ -444,7 +444,7 @@ def get_type(self): return type(self.obj).__name__ -class TreeTraversal(Traversal): +class TreeTraversal(Traversal): # type: ignore[misc] def get_children(self, node): return node.get_children()