Skip to content
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

Fix final typing errors #1939

Merged
merged 1 commit into from
Jun 1, 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
27 changes: 0 additions & 27 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -198,33 +198,6 @@ module = [
]
ignore_errors = true

[[tool.mypy.overrides]]
module = [
"tests.*",
]
check_untyped_defs = false

[[tool.mypy.overrides]]
module = [
"zarr.array",
"zarr.buffer"
]
disallow_untyped_calls = false

[[tool.mypy.overrides]]
module = [
"zarr.array",
]
disallow_untyped_defs = false


[[tool.mypy.overrides]]
module = [
"zarr.metadata",
"zarr.store.remote"
]
warn_return_any = false

[tool.pytest.ini_options]
minversion = "7"
testpaths = ["tests"]
Expand Down
6 changes: 3 additions & 3 deletions src/zarr/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,8 @@ async def update_attributes(self, new_attributes: dict[str, JSON]) -> AsyncArray
def __repr__(self) -> str:
return f"<AsyncArray {self.store_path} shape={self.shape} dtype={self.dtype}>"

async def info(self):
return NotImplemented
async def info(self) -> None:
raise NotImplementedError


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

def info(self):
def info(self) -> None:
return sync(
self._async_array.info(),
)
19 changes: 10 additions & 9 deletions src/zarr/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ def _json_convert(o: np.dtype[Any] | Enum | Codec) -> str | dict[str, Any]:
# this serializes numcodecs compressors
# todo: implement to_dict for codecs
elif isinstance(o, numcodecs.abc.Codec):
return o.get_config()
config: dict[str, Any] = o.get_config()
return config
raise TypeError

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

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

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

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

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


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


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


# todo: real validation
def parse_filters(data: Any) -> list[dict[str, JSON]]:
def parse_filters(data: list[dict[str, JSON]] | None) -> list[dict[str, JSON]] | None:
return data


# todo: real validation
def parse_compressor(data: Any) -> dict[str, JSON] | None:
def parse_compressor(data: dict[str, JSON] | None) -> dict[str, JSON] | None:
return data


Expand Down
5 changes: 3 additions & 2 deletions src/zarr/store/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async def get(
path = _dereference_path(root, key)

try:
value = await (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not 100% correct but I think it can be fixed in #1785

value: Buffer | None = await (
fs._cat_file(path, start=byte_range[0], end=byte_range[1])
if byte_range
else fs._cat_file(path)
Expand Down Expand Up @@ -96,4 +96,5 @@ async def delete(self, key: str) -> None:
async def exists(self, key: str) -> bool:
fs, root = self._make_fs()
path = _dereference_path(root, key)
return await fs._exists(path)
exists: bool = await fs._exists(path)
return exists