Skip to content

Commit 19365e2

Browse files
authored
Fix final typing errors (#1939)
1 parent bd6cf32 commit 19365e2

File tree

4 files changed

+16
-41
lines changed

4 files changed

+16
-41
lines changed

pyproject.toml

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -198,33 +198,6 @@ module = [
198198
]
199199
ignore_errors = true
200200

201-
[[tool.mypy.overrides]]
202-
module = [
203-
"tests.*",
204-
]
205-
check_untyped_defs = false
206-
207-
[[tool.mypy.overrides]]
208-
module = [
209-
"zarr.array",
210-
"zarr.buffer"
211-
]
212-
disallow_untyped_calls = false
213-
214-
[[tool.mypy.overrides]]
215-
module = [
216-
"zarr.array",
217-
]
218-
disallow_untyped_defs = false
219-
220-
221-
[[tool.mypy.overrides]]
222-
module = [
223-
"zarr.metadata",
224-
"zarr.store.remote"
225-
]
226-
warn_return_any = false
227-
228201
[tool.pytest.ini_options]
229202
minversion = "7"
230203
testpaths = ["tests"]

src/zarr/array.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ async def update_attributes(self, new_attributes: dict[str, JSON]) -> AsyncArray
473473
def __repr__(self) -> str:
474474
return f"<AsyncArray {self.store_path} shape={self.shape} dtype={self.dtype}>"
475475

476-
async def info(self):
477-
return NotImplemented
476+
async def info(self) -> None:
477+
raise NotImplementedError
478478

479479

480480
@dataclass(frozen=True)
@@ -609,7 +609,7 @@ def update_attributes(self, new_attributes: dict[str, JSON]) -> Array:
609609
def __repr__(self) -> str:
610610
return f"<Array {self.store_path} shape={self.shape} dtype={self.dtype}>"
611611

612-
def info(self):
612+
def info(self) -> None:
613613
return sync(
614614
self._async_array.info(),
615615
)

src/zarr/metadata.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ def _json_convert(o: np.dtype[Any] | Enum | Codec) -> str | dict[str, Any]:
261261
# this serializes numcodecs compressors
262262
# todo: implement to_dict for codecs
263263
elif isinstance(o, numcodecs.abc.Codec):
264-
return o.get_config()
264+
config: dict[str, Any] = o.get_config()
265+
return config
265266
raise TypeError
266267

267268
return {
@@ -270,14 +271,14 @@ def _json_convert(o: np.dtype[Any] | Enum | Codec) -> str | dict[str, Any]:
270271

271272
@classmethod
272273
def from_dict(cls, data: dict[str, JSON]) -> ArrayV3Metadata:
274+
# TODO: Remove the type: ignores[] comments below and use a TypedDict to type `data`
273275
# check that the zarr_format attribute is correct
274-
_ = parse_zarr_format_v3(data.pop("zarr_format"))
276+
_ = parse_zarr_format_v3(data.pop("zarr_format")) # type: ignore[arg-type]
275277
# check that the node_type attribute is correct
276-
_ = parse_node_type_array(data.pop("node_type"))
278+
_ = parse_node_type_array(data.pop("node_type")) # type: ignore[arg-type]
277279

278280
data["dimension_names"] = data.pop("dimension_names", None)
279281

280-
# TODO: Remove the ignores and use a TypedDict to type `data`
281282
return cls(**data) # type: ignore[arg-type]
282283

283284
def to_dict(self) -> dict[str, Any]:
@@ -450,32 +451,32 @@ def parse_attributes(data: None | dict[str, JSON]) -> dict[str, JSON]:
450451
# todo: move to its own module and drop _v3 suffix
451452
# todo: consider folding all the literal parsing into a single function
452453
# that takes 2 arguments
453-
def parse_zarr_format_v3(data: Any) -> Literal[3]:
454+
def parse_zarr_format_v3(data: Literal[3]) -> Literal[3]:
454455
if data == 3:
455456
return data
456457
raise ValueError(f"Invalid value. Expected 3. Got {data}.")
457458

458459

459460
# todo: move to its own module and drop _v2 suffix
460-
def parse_zarr_format_v2(data: Any) -> Literal[2]:
461+
def parse_zarr_format_v2(data: Literal[2]) -> Literal[2]:
461462
if data == 2:
462463
return data
463464
raise ValueError(f"Invalid value. Expected 2. Got {data}.")
464465

465466

466-
def parse_node_type_array(data: Any) -> Literal["array"]:
467+
def parse_node_type_array(data: Literal["array"]) -> Literal["array"]:
467468
if data == "array":
468469
return data
469470
raise ValueError(f"Invalid value. Expected 'array'. Got {data}.")
470471

471472

472473
# todo: real validation
473-
def parse_filters(data: Any) -> list[dict[str, JSON]]:
474+
def parse_filters(data: list[dict[str, JSON]] | None) -> list[dict[str, JSON]] | None:
474475
return data
475476

476477

477478
# todo: real validation
478-
def parse_compressor(data: Any) -> dict[str, JSON] | None:
479+
def parse_compressor(data: dict[str, JSON] | None) -> dict[str, JSON] | None:
479480
return data
480481

481482

src/zarr/store/remote.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async def get(
6262
path = _dereference_path(root, key)
6363

6464
try:
65-
value = await (
65+
value: Buffer | None = await (
6666
fs._cat_file(path, start=byte_range[0], end=byte_range[1])
6767
if byte_range
6868
else fs._cat_file(path)
@@ -96,4 +96,5 @@ async def delete(self, key: str) -> None:
9696
async def exists(self, key: str) -> bool:
9797
fs, root = self._make_fs()
9898
path = _dereference_path(root, key)
99-
return await fs._exists(path)
99+
exists: bool = await fs._exists(path)
100+
return exists

0 commit comments

Comments
 (0)