diff --git a/pyproject.toml b/pyproject.toml index 3dcda98980..8244947a1e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -166,6 +166,8 @@ check_untyped_defs = true disallow_untyped_decorators = true disallow_any_generics = true +disallow_incomplete_defs = true + [[tool.mypy.overrides]] module = [ "zarr.v2._storage.store", @@ -196,6 +198,13 @@ module = [ ] disallow_any_generics = false +[[tool.mypy.overrides]] +module = [ + "zarr.v2.*", + "zarr.array_v2", + "zarr.group" +] +disallow_incomplete_defs = false [tool.pytest.ini_options] doctest_optionflags = [ diff --git a/src/zarr/array.py b/src/zarr/array.py index c1263230c0..18e26b64dd 100644 --- a/src/zarr/array.py +++ b/src/zarr/array.py @@ -39,7 +39,7 @@ from zarr.sync import sync -def parse_array_metadata(data: Any): +def parse_array_metadata(data: Any) -> ArrayMetadata: if isinstance(data, ArrayMetadata): return data elif isinstance(data, dict): @@ -192,7 +192,7 @@ def dtype(self) -> np.dtype: def attrs(self) -> dict: return self.metadata.attributes - async def getitem(self, selection: Selection): + async def getitem(self, selection: Selection) -> np.ndarray: assert isinstance(self.metadata.chunk_grid, RegularChunkGrid) indexer = BasicIndexer( selection, @@ -231,7 +231,7 @@ async def _read_chunk( chunk_selection: SliceSelection, out_selection: SliceSelection, out: np.ndarray, - ): + ) -> None: chunk_spec = self.metadata.get_chunk_spec(chunk_coords) chunk_key_encoding = self.metadata.chunk_key_encoding chunk_key = chunk_key_encoding.encode_chunk_key(chunk_coords) @@ -301,7 +301,7 @@ async def _write_chunk( chunk_coords: ChunkCoords, chunk_selection: SliceSelection, out_selection: SliceSelection, - ): + ) -> None: chunk_spec = self.metadata.get_chunk_spec(chunk_coords) chunk_key_encoding = self.metadata.chunk_key_encoding chunk_key = chunk_key_encoding.encode_chunk_key(chunk_coords) @@ -350,7 +350,7 @@ async def _write_chunk( async def _write_chunk_to_store( self, store_path: StorePath, chunk_array: np.ndarray, chunk_spec: ArraySpec - ): + ) -> None: if np.all(chunk_array == self.metadata.fill_value): # chunks that only contain fill_value will be removed await store_path.delete() @@ -514,7 +514,7 @@ def metadata(self) -> ArrayMetadata: def store_path(self) -> StorePath: return self._async_array.store_path - def __getitem__(self, selection: Selection): + def __getitem__(self, selection: Selection) -> np.ndarray: return sync( self._async_array.getitem(selection), self._async_array.runtime_configuration.asyncio_loop, diff --git a/src/zarr/codecs/sharding.py b/src/zarr/codecs/sharding.py index 948e46f132..d4f8b7dfc9 100644 --- a/src/zarr/codecs/sharding.py +++ b/src/zarr/codecs/sharding.py @@ -195,7 +195,7 @@ def create_empty(cls, chunks_per_shard: ChunkCoords) -> _ShardBuilder: obj.index = _ShardIndex.create_empty(chunks_per_shard) return obj - def append(self, chunk_coords: ChunkCoords, value: BytesLike): + def append(self, chunk_coords: ChunkCoords, value: BytesLike) -> None: chunk_start = len(self.buf) chunk_length = len(value) self.buf.extend(value) @@ -424,7 +424,7 @@ async def _read_chunk( shard_spec: ArraySpec, runtime_configuration: RuntimeConfiguration, out: np.ndarray, - ): + ) -> None: chunk_spec = self._get_chunk_spec(shard_spec) chunk_bytes = shard_dict.get(chunk_coords, None) if chunk_bytes is not None: diff --git a/src/zarr/indexing.py b/src/zarr/indexing.py index 7c1a4df226..75bed63384 100644 --- a/src/zarr/indexing.py +++ b/src/zarr/indexing.py @@ -13,7 +13,7 @@ def _ensure_tuple(v: Selection) -> SliceSelection: return v -def _err_too_many_indices(selection: SliceSelection, shape: ChunkCoords): +def _err_too_many_indices(selection: SliceSelection, shape: ChunkCoords) -> None: raise IndexError( "too many indices for array; expected {}, got {}".format(len(shape), len(selection)) ) @@ -23,7 +23,7 @@ def _err_negative_step(): raise IndexError("only slices with step >= 1 are supported") -def _check_selection_length(selection: SliceSelection, shape: ChunkCoords): +def _check_selection_length(selection: SliceSelection, shape: ChunkCoords) -> None: if len(selection) > len(shape): _err_too_many_indices(selection, shape) @@ -179,7 +179,7 @@ def c_order_iter(chunks_per_shard: ChunkCoords) -> Iterator[ChunkCoords]: return itertools.product(*(range(x) for x in chunks_per_shard)) -def is_total_slice(item: Selection, shape: ChunkCoords): +def is_total_slice(item: Selection, shape: ChunkCoords) -> bool: """Determine whether `item` specifies a complete slice of array with the given `shape`. Used to optimize __setitem__ operations on the Chunk class.""" diff --git a/src/zarr/store/local.py b/src/zarr/store/local.py index 1e9e880875..73e3c6c0e1 100644 --- a/src/zarr/store/local.py +++ b/src/zarr/store/local.py @@ -34,13 +34,14 @@ def _put( value: BytesLike, start: Optional[int] = None, auto_mkdir: bool = True, -): +) -> int | None: if auto_mkdir: path.parent.mkdir(parents=True, exist_ok=True) if start is not None: with path.open("r+b") as f: f.seek(start) f.write(value) + return None else: return path.write_bytes(value)