From 0a7d1828ed9d6c5100ec994d53a363dc93fa374f Mon Sep 17 00:00:00 2001 From: David Stansby Date: Fri, 24 May 2024 10:33:41 +0100 Subject: [PATCH 1/3] Clean up v2 mypy ignores --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 4bcbfd0a0a..7fc061fb8b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -204,6 +204,7 @@ disallow_untyped_defs = true no_implicit_reexport = true + [[tool.mypy.overrides]] module = [ "zarr.v2.*", From 90bebb349b38572face5a70712ef5b989bfa78c2 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Fri, 24 May 2024 10:42:02 +0100 Subject: [PATCH 2/3] Enable extra mypy error codes --- pyproject.toml | 1 + src/zarr/buffer.py | 2 +- src/zarr/codecs/sharding.py | 2 +- src/zarr/indexing.py | 7 ++----- src/zarr/metadata.py | 7 ++++--- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7fc061fb8b..65f5ffa0bf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -204,6 +204,7 @@ disallow_untyped_defs = true no_implicit_reexport = true +enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] [[tool.mypy.overrides]] module = [ diff --git a/src/zarr/buffer.py b/src/zarr/buffer.py index 0f055093c1..59994e70d6 100644 --- a/src/zarr/buffer.py +++ b/src/zarr/buffer.py @@ -79,7 +79,7 @@ def ravel(self, order: Literal["K", "A", "C", "F"] = "C") -> Self: ... def all(self) -> bool: ... - def __eq__(self, other: Any) -> Self: # type: ignore + def __eq__(self, other: Any) -> Self: # type: ignore[explicit-override, override] """Element-wise equal Notice diff --git a/src/zarr/codecs/sharding.py b/src/zarr/codecs/sharding.py index ec5306ee80..21cc520daf 100644 --- a/src/zarr/codecs/sharding.py +++ b/src/zarr/codecs/sharding.py @@ -205,7 +205,7 @@ def merge_with_morton_order( ) -> _ShardBuilder: obj = cls.create_empty(chunks_per_shard) for chunk_coords in morton_order_iter(chunks_per_shard): - if tombstones is not None and chunk_coords in tombstones: + if chunk_coords in tombstones: continue for shard_dict in shard_dicts: maybe_value = shard_dict.get(chunk_coords, None) diff --git a/src/zarr/indexing.py b/src/zarr/indexing.py index 45413bc5b2..6bc83d5062 100644 --- a/src/zarr/indexing.py +++ b/src/zarr/indexing.py @@ -199,11 +199,8 @@ def is_total_slice(item: Selection, shape: ChunkCoords) -> bool: if isinstance(item, tuple): return all( ( - isinstance(dim_sel, slice) - and ( - (dim_sel == slice(None)) - or ((dim_sel.stop - dim_sel.start == dim_len) and (dim_sel.step in [1, None])) - ) + (dim_sel == slice(None)) + or ((dim_sel.stop - dim_sel.start == dim_len) and (dim_sel.step in [1, None])) ) for dim_sel, dim_len in zip(item, shape, strict=False) ) diff --git a/src/zarr/metadata.py b/src/zarr/metadata.py index 2d8a455152..29d0d19a06 100644 --- a/src/zarr/metadata.py +++ b/src/zarr/metadata.py @@ -432,10 +432,11 @@ def update_attributes(self, attributes: dict[str, JSON]) -> Self: def parse_dimension_names(data: None | Iterable[str]) -> tuple[str, ...] | None: if data is None: return data - if isinstance(data, Iterable) and all([isinstance(x, str) for x in data]): + elif all([isinstance(x, str) for x in data]): return tuple(data) - msg = f"Expected either None or a iterable of str, got {type(data)}" - raise TypeError(msg) + else: + msg = f"Expected either None or a iterable of str, got {type(data)}" + raise TypeError(msg) # todo: real validation From e337a555c05e3aa2f2c9f2411bf0d44f63f24b0b Mon Sep 17 00:00:00 2001 From: David Stansby Date: Fri, 31 May 2024 23:06:01 +0100 Subject: [PATCH 3/3] Specific error code --- src/zarr/testing/store.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zarr/testing/store.py b/src/zarr/testing/store.py index b317f383f6..cb4dc9f7b5 100644 --- a/src/zarr/testing/store.py +++ b/src/zarr/testing/store.py @@ -47,7 +47,7 @@ def test_store_mode(self, store: S, store_kwargs: dict[str, Any]) -> None: assert store.writeable with pytest.raises(AttributeError): - store.mode = "w" # type: ignore + store.mode = "w" # type: ignore[misc] # read-only kwargs = {**store_kwargs, "mode": "r"}