Skip to content

Update pre-commit hooks + mypy fixes #3133

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repos:
- id: check-yaml
- id: trailing-whitespace
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.15.0
rev: v1.16.1
hooks:
- id: mypy
files: src|tests
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/core/buffer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def ravel(self, order: Literal["K", "A", "C", "F"] = ...) -> Self: ...

def all(self) -> bool: ...

def __eq__(self, other: object) -> Self: # type: ignore[explicit-override, override]
def __eq__(self, other: object) -> Self: # type: ignore[override]
"""Element-wise equal

Notes
Expand Down
4 changes: 2 additions & 2 deletions src/zarr/core/dtype/npy/bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@ def _check_native_dtype(
Bool
True if the dtype matches, False otherwise.
"""
return cls.dtype_cls is type(dtype) and dtype.fields is None # type: ignore[has-type]
return cls.dtype_cls is type(dtype) and dtype.fields is None

@classmethod
def from_native_dtype(cls, dtype: TBaseDType) -> Self:
if cls._check_native_dtype(dtype):
return cls(length=dtype.itemsize)
raise DataTypeValidationError(
f"Invalid data type: {dtype}. Expected an instance of {cls.dtype_cls}" # type: ignore[has-type]
f"Invalid data type: {dtype}. Expected an instance of {cls.dtype_cls}"
)

def to_native_dtype(self) -> np.dtypes.VoidDType[int]:
Expand Down
4 changes: 2 additions & 2 deletions src/zarr/core/dtype/npy/structured.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _check_native_dtype(cls, dtype: TBaseDType) -> TypeGuard[np.dtypes.VoidDType
TypeGuard[np.dtypes.VoidDType]
True if the dtype matches, False otherwise.
"""
return isinstance(dtype, cls.dtype_cls) and dtype.fields is not None # type: ignore[has-type]
return isinstance(dtype, cls.dtype_cls) and dtype.fields is not None

@classmethod
def from_native_dtype(cls, dtype: TBaseDType) -> Self:
Expand All @@ -68,7 +68,7 @@ def from_native_dtype(cls, dtype: TBaseDType) -> Self:

return cls(fields=tuple(fields))
raise DataTypeValidationError(
f"Invalid data type: {dtype}. Expected an instance of {cls.dtype_cls}" # type: ignore[has-type]
f"Invalid data type: {dtype}. Expected an instance of {cls.dtype_cls}"
)

def to_native_dtype(self) -> np.dtypes.VoidDType[int]:
Expand Down
4 changes: 2 additions & 2 deletions src/zarr/core/dtype/npy/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def _from_json_v2(cls, data: DTypeJSON) -> Self:
return cls.from_native_dtype(np.dtype(name))
msg = (
f"Invalid JSON representation of {cls.__name__}. Got {data!r}, expected a string "
f"representation of an instance of {cls.dtype_cls}" # type: ignore[has-type]
f"representation of an instance of {cls.dtype_cls}"
)
raise DataTypeValidationError(msg)

Expand Down Expand Up @@ -318,7 +318,7 @@ def _from_json_v2(cls, data: DTypeJSON) -> Self:
return cls.from_native_dtype(np.dtype(name))
msg = (
f"Invalid JSON representation of {cls.__name__}. Got {data!r}, expected a string "
f"representation of an instance of {cls.dtype_cls}" # type: ignore[has-type]
f"representation of an instance of {cls.dtype_cls}"
)
raise DataTypeValidationError(msg)

Expand Down
4 changes: 3 additions & 1 deletion src/zarr/storage/_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ async def delete(self, key: str) -> None:
except KeyError:
logger.debug("Key %s does not exist.", key)

async def set_partial_values(self, key_start_values: Iterable[tuple[str, int, bytes]]) -> None:
async def set_partial_values(
self, key_start_values: Iterable[tuple[str, int, bytes | bytearray | memoryview[int]]]
) -> None:
# docstring inherited
raise NotImplementedError

Expand Down
4 changes: 3 additions & 1 deletion src/zarr/storage/_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ async def set(self, key: str, value: Buffer) -> None:
with self._lock:
self._set(key, value)

async def set_partial_values(self, key_start_values: Iterable[tuple[str, int, bytes]]) -> None:
async def set_partial_values(
self, key_start_values: Iterable[tuple[str, int, bytes | bytearray | memoryview[int]]]
) -> None:
raise NotImplementedError

async def set_if_not_exists(self, key: str, value: Buffer) -> None:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
)

if TYPE_CHECKING:
from zarr.core.dtype.wrapper import ZDType
from zarr.core.dtype.wrapper import TBaseDType, TBaseScalar, ZDType


def test_config_defaults_set() -> None:
Expand Down Expand Up @@ -329,9 +329,9 @@ async def test_default_codecs(dtype_category: str) -> None:
"""
Test that the default compressors are sensitive to the current setting of the config.
"""
zdtype: ZDType[Any, Any]
zdtype: ZDType[TBaseDType, TBaseScalar]
if dtype_category == "variable-length-string":
zdtype = VariableLengthUTF8()
zdtype = VariableLengthUTF8() # type: ignore[assignment]
else:
zdtype = Int8()
expected_compressors = (GzipCodec(),)
Expand Down