Skip to content

Disallow untyped defs #1834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
asyncio_mode = "auto"
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)
Loading