Skip to content

Commit 5889e96

Browse files
authored
Disallow incomplete type definitions (#1814)
1 parent 096c900 commit 5889e96

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ check_untyped_defs = true
166166
disallow_untyped_decorators = true
167167
disallow_any_generics = true
168168

169+
disallow_incomplete_defs = true
170+
169171
[[tool.mypy.overrides]]
170172
module = [
171173
"zarr.v2._storage.store",
@@ -196,6 +198,13 @@ module = [
196198
]
197199
disallow_any_generics = false
198200

201+
[[tool.mypy.overrides]]
202+
module = [
203+
"zarr.v2.*",
204+
"zarr.array_v2",
205+
"zarr.group"
206+
]
207+
disallow_incomplete_defs = false
199208

200209
[tool.pytest.ini_options]
201210
doctest_optionflags = [

src/zarr/array.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from zarr.sync import sync
4040

4141

42-
def parse_array_metadata(data: Any):
42+
def parse_array_metadata(data: Any) -> ArrayMetadata:
4343
if isinstance(data, ArrayMetadata):
4444
return data
4545
elif isinstance(data, dict):
@@ -192,7 +192,7 @@ def dtype(self) -> np.dtype:
192192
def attrs(self) -> dict:
193193
return self.metadata.attributes
194194

195-
async def getitem(self, selection: Selection):
195+
async def getitem(self, selection: Selection) -> np.ndarray:
196196
assert isinstance(self.metadata.chunk_grid, RegularChunkGrid)
197197
indexer = BasicIndexer(
198198
selection,
@@ -231,7 +231,7 @@ async def _read_chunk(
231231
chunk_selection: SliceSelection,
232232
out_selection: SliceSelection,
233233
out: np.ndarray,
234-
):
234+
) -> None:
235235
chunk_spec = self.metadata.get_chunk_spec(chunk_coords)
236236
chunk_key_encoding = self.metadata.chunk_key_encoding
237237
chunk_key = chunk_key_encoding.encode_chunk_key(chunk_coords)
@@ -301,7 +301,7 @@ async def _write_chunk(
301301
chunk_coords: ChunkCoords,
302302
chunk_selection: SliceSelection,
303303
out_selection: SliceSelection,
304-
):
304+
) -> None:
305305
chunk_spec = self.metadata.get_chunk_spec(chunk_coords)
306306
chunk_key_encoding = self.metadata.chunk_key_encoding
307307
chunk_key = chunk_key_encoding.encode_chunk_key(chunk_coords)
@@ -350,7 +350,7 @@ async def _write_chunk(
350350

351351
async def _write_chunk_to_store(
352352
self, store_path: StorePath, chunk_array: np.ndarray, chunk_spec: ArraySpec
353-
):
353+
) -> None:
354354
if np.all(chunk_array == self.metadata.fill_value):
355355
# chunks that only contain fill_value will be removed
356356
await store_path.delete()
@@ -514,7 +514,7 @@ def metadata(self) -> ArrayMetadata:
514514
def store_path(self) -> StorePath:
515515
return self._async_array.store_path
516516

517-
def __getitem__(self, selection: Selection):
517+
def __getitem__(self, selection: Selection) -> np.ndarray:
518518
return sync(
519519
self._async_array.getitem(selection),
520520
self._async_array.runtime_configuration.asyncio_loop,

src/zarr/codecs/sharding.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def create_empty(cls, chunks_per_shard: ChunkCoords) -> _ShardBuilder:
195195
obj.index = _ShardIndex.create_empty(chunks_per_shard)
196196
return obj
197197

198-
def append(self, chunk_coords: ChunkCoords, value: BytesLike):
198+
def append(self, chunk_coords: ChunkCoords, value: BytesLike) -> None:
199199
chunk_start = len(self.buf)
200200
chunk_length = len(value)
201201
self.buf.extend(value)
@@ -424,7 +424,7 @@ async def _read_chunk(
424424
shard_spec: ArraySpec,
425425
runtime_configuration: RuntimeConfiguration,
426426
out: np.ndarray,
427-
):
427+
) -> None:
428428
chunk_spec = self._get_chunk_spec(shard_spec)
429429
chunk_bytes = shard_dict.get(chunk_coords, None)
430430
if chunk_bytes is not None:

src/zarr/indexing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def _ensure_tuple(v: Selection) -> SliceSelection:
1313
return v
1414

1515

16-
def _err_too_many_indices(selection: SliceSelection, shape: ChunkCoords):
16+
def _err_too_many_indices(selection: SliceSelection, shape: ChunkCoords) -> None:
1717
raise IndexError(
1818
"too many indices for array; expected {}, got {}".format(len(shape), len(selection))
1919
)
@@ -23,7 +23,7 @@ def _err_negative_step():
2323
raise IndexError("only slices with step >= 1 are supported")
2424

2525

26-
def _check_selection_length(selection: SliceSelection, shape: ChunkCoords):
26+
def _check_selection_length(selection: SliceSelection, shape: ChunkCoords) -> None:
2727
if len(selection) > len(shape):
2828
_err_too_many_indices(selection, shape)
2929

@@ -179,7 +179,7 @@ def c_order_iter(chunks_per_shard: ChunkCoords) -> Iterator[ChunkCoords]:
179179
return itertools.product(*(range(x) for x in chunks_per_shard))
180180

181181

182-
def is_total_slice(item: Selection, shape: ChunkCoords):
182+
def is_total_slice(item: Selection, shape: ChunkCoords) -> bool:
183183
"""Determine whether `item` specifies a complete slice of array with the
184184
given `shape`. Used to optimize __setitem__ operations on the Chunk
185185
class."""

src/zarr/store/local.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ def _put(
3434
value: BytesLike,
3535
start: Optional[int] = None,
3636
auto_mkdir: bool = True,
37-
):
37+
) -> int | None:
3838
if auto_mkdir:
3939
path.parent.mkdir(parents=True, exist_ok=True)
4040
if start is not None:
4141
with path.open("r+b") as f:
4242
f.seek(start)
4343
f.write(value)
44+
return None
4445
else:
4546
return path.write_bytes(value)
4647

0 commit comments

Comments
 (0)