Skip to content

Commit

Permalink
Disallow untyped defs
Browse files Browse the repository at this point in the history
  • Loading branch information
dstansby committed May 7, 2024
1 parent dd0ea50 commit 4995998
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ disallow_any_generics = true
disallow_incomplete_defs = true
disallow_untyped_calls = true

disallow_untyped_defs = true

[[tool.mypy.overrides]]
module = [
"zarr.v2.*",
Expand Down Expand Up @@ -211,6 +213,16 @@ module = [
]
disallow_untyped_calls = false

[[tool.mypy.overrides]]
module = [
"zarr.v2.*",
"zarr.array_v2",
"zarr.array",
"zarr.common",
"zarr.group",
"zarr.metadata"
]
disallow_untyped_defs = false

[tool.pytest.ini_options]
doctest_optionflags = [
Expand Down
7 changes: 4 additions & 3 deletions src/zarr/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

# from zarr.array_v2 import ArrayV2
from zarr.codecs import BytesCodec
from zarr.codecs.pipeline import CodecPipeline
from zarr.common import (
ZARR_JSON,
ArraySpec,
Expand Down Expand Up @@ -55,7 +56,7 @@ class AsyncArray:
runtime_configuration: RuntimeConfiguration

@property
def codecs(self):
def codecs(self) -> CodecPipeline:
return self.metadata.codecs

def __init__(
Expand Down Expand Up @@ -402,7 +403,7 @@ async def update_attributes(self, new_attributes: Dict[str, Any]) -> AsyncArray:
await (self.store_path / ZARR_JSON).set(new_metadata.to_bytes())
return replace(self, metadata=new_metadata)

def __repr__(self):
def __repr__(self) -> str:
return f"<AsyncArray {self.store_path} shape={self.shape} dtype={self.dtype}>"

async def info(self):
Expand Down Expand Up @@ -542,7 +543,7 @@ def update_attributes(self, new_attributes: Dict[str, Any]) -> Array:
)
)

def __repr__(self):
def __repr__(self) -> str:
return f"<Array {self.store_path} shape={self.shape} dtype={self.dtype}>"

def info(self):
Expand Down
12 changes: 6 additions & 6 deletions src/zarr/attributes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations
from collections.abc import MutableMapping
from typing import TYPE_CHECKING, Any, Union
from typing import TYPE_CHECKING, Any, Iterator, Union

if TYPE_CHECKING:
from zarr.group import Group
Expand All @@ -12,21 +12,21 @@ def __init__(self, obj: Union[Array, Group]):
# key=".zattrs", read_only=False, cache=True, synchronizer=None
self._obj = obj

def __getitem__(self, key):
def __getitem__(self, key: str) -> Any:
return self._obj.metadata.attributes[key]

def __setitem__(self, key, value):
def __setitem__(self, key: str, value: Any) -> None:
new_attrs = dict(self._obj.metadata.attributes)
new_attrs[key] = value
self._obj = self._obj.update_attributes(new_attrs)

def __delitem__(self, key):
def __delitem__(self, key: str) -> None:
new_attrs = dict(self._obj.metadata.attributes)
del new_attrs[key]
self._obj = self._obj.update_attributes(new_attrs)

def __iter__(self):
def __iter__(self) -> Iterator[str]:
return iter(self._obj.metadata.attributes)

def __len__(self):
def __len__(self) -> int:
return len(self._obj.metadata.attributes)

0 comments on commit 4995998

Please sign in to comment.