Skip to content

Commit 70af54a

Browse files
authored
Fix typing in test_codecs (#3095)
1 parent 26811eb commit 70af54a

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,14 @@ module = [
364364
"tests.test_store.test_local",
365365
"tests.test_store.test_fsspec",
366366
"tests.test_store.test_memory",
367+
"tests.test_codecs.test_codecs",
367368
]
368369
strict = false
369370

370371
# TODO: Move the next modules up to the strict = false section
371372
# and fix the errors
372373
[[tool.mypy.overrides]]
373374
module = [
374-
"tests.test_codecs.test_codecs",
375375
"tests.test_metadata.*",
376376
"tests.test_store.test_core",
377377
"tests.test_store.test_logging",

tests/test_codecs/test_codecs.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import json
44
from dataclasses import dataclass
5-
from typing import TYPE_CHECKING
5+
from typing import TYPE_CHECKING, Any
66

77
import numpy as np
88
import pytest
@@ -18,32 +18,33 @@
1818
TransposeCodec,
1919
)
2020
from zarr.core.buffer import default_buffer_prototype
21-
from zarr.core.indexing import Selection, morton_order_iter
21+
from zarr.core.indexing import BasicSelection, morton_order_iter
22+
from zarr.core.metadata.v3 import ArrayV3Metadata
2223
from zarr.storage import StorePath
2324

2425
if TYPE_CHECKING:
2526
from zarr.abc.store import Store
26-
from zarr.core.buffer import NDArrayLike
27-
from zarr.core.common import MemoryOrder
27+
from zarr.core.buffer.core import NDArrayLikeOrScalar
28+
from zarr.core.common import ChunkCoords, MemoryOrder
2829

2930

3031
@dataclass(frozen=True)
3132
class _AsyncArrayProxy:
32-
array: AsyncArray
33+
array: AsyncArray[Any]
3334

34-
def __getitem__(self, selection: Selection) -> _AsyncArraySelectionProxy:
35+
def __getitem__(self, selection: BasicSelection) -> _AsyncArraySelectionProxy:
3536
return _AsyncArraySelectionProxy(self.array, selection)
3637

3738

3839
@dataclass(frozen=True)
3940
class _AsyncArraySelectionProxy:
40-
array: AsyncArray
41-
selection: Selection
41+
array: AsyncArray[Any]
42+
selection: BasicSelection
4243

43-
async def get(self) -> NDArrayLike:
44+
async def get(self) -> NDArrayLikeOrScalar:
4445
return await self.array.getitem(self.selection)
4546

46-
async def set(self, value: np.ndarray) -> None:
47+
async def set(self, value: np.ndarray[Any, Any]) -> None:
4748
return await self.array.setitem(self.selection, value)
4849

4950

@@ -101,6 +102,7 @@ async def test_order(
101102
read_data = await _AsyncArrayProxy(a)[:, :].get()
102103
assert np.array_equal(data, read_data)
103104

105+
assert isinstance(read_data, np.ndarray)
104106
if runtime_read_order == "F":
105107
assert read_data.flags["F_CONTIGUOUS"]
106108
assert not read_data.flags["C_CONTIGUOUS"]
@@ -142,6 +144,7 @@ def test_order_implicit(
142144
read_data = a[:, :]
143145
assert np.array_equal(data, read_data)
144146

147+
assert isinstance(read_data, np.ndarray)
145148
if runtime_read_order == "F":
146149
assert read_data.flags["F_CONTIGUOUS"]
147150
assert not read_data.flags["C_CONTIGUOUS"]
@@ -209,7 +212,7 @@ def test_morton() -> None:
209212
[3, 2, 1, 6, 4, 5, 2],
210213
],
211214
)
212-
def test_morton2(shape) -> None:
215+
def test_morton2(shape: ChunkCoords) -> None:
213216
order = list(morton_order_iter(shape))
214217
for i, x in enumerate(order):
215218
assert x not in order[:i] # no duplicates
@@ -263,7 +266,10 @@ async def test_dimension_names(store: Store) -> None:
263266
dimension_names=("x", "y"),
264267
)
265268

266-
assert (await zarr.api.asynchronous.open_array(store=spath)).metadata.dimension_names == (
269+
assert isinstance(
270+
meta := (await zarr.api.asynchronous.open_array(store=spath)).metadata, ArrayV3Metadata
271+
)
272+
assert meta.dimension_names == (
267273
"x",
268274
"y",
269275
)
@@ -277,7 +283,8 @@ async def test_dimension_names(store: Store) -> None:
277283
fill_value=0,
278284
)
279285

280-
assert (await AsyncArray.open(spath2)).metadata.dimension_names is None
286+
assert isinstance(meta := (await AsyncArray.open(spath2)).metadata, ArrayV3Metadata)
287+
assert meta.dimension_names is None
281288
zarr_json_buffer = await store.get(f"{path2}/zarr.json", prototype=default_buffer_prototype())
282289
assert zarr_json_buffer is not None
283290
assert "dimension_names" not in json.loads(zarr_json_buffer.to_bytes())

0 commit comments

Comments
 (0)