From 8c583284e75bfb354725cf53eaaefa27f47a0031 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Mon, 18 Dec 2023 20:03:46 +0000 Subject: [PATCH] Check untyped defs in zarr.core --- pyproject.toml | 1 - zarr/core.py | 20 ++++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c1fee48ec..123c5f83a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -130,7 +130,6 @@ check_untyped_defs = true [[tool.mypy.overrides]] module = [ "zarr.tests.*", - "zarr.core", "zarr._storage.*" ] check_untyped_defs = false diff --git a/zarr/core.py b/zarr/core.py index c3184c665..d6ac40484 100644 --- a/zarr/core.py +++ b/zarr/core.py @@ -1977,11 +1977,11 @@ def _set_selection(self, indexer, value, fields=None): chunk_value = value[out_selection] # handle missing singleton dimensions if indexer.drop_axes: + item: list[slice | None] item = [slice(None)] * self.ndim for a in indexer.drop_axes: item[a] = np.newaxis - item = tuple(item) - chunk_value = chunk_value[item] + chunk_value = chunk_value[tuple(item)] # put data self._chunk_setitem(chunk_coords, chunk_selection, chunk_value, fields=fields) @@ -2000,8 +2000,7 @@ def _set_selection(self, indexer, value, fields=None): item = [slice(None)] * self.ndim for a in indexer.drop_axes: item[a] = np.newaxis - item = tuple(item) - cv = chunk_value[item] + cv = chunk_value[tuple(item)] chunk_values.append(cv) self._chunk_setitems(lchunk_coords, lchunk_selection, chunk_values, fields=fields) @@ -2129,6 +2128,7 @@ def _chunk_getitems( # Keys to retrieve ckeys = [self._chunk_key(ch) for ch in lchunk_coords] + cdatas: dict[str, PartialReadBuffer | UncompressedPartialReadBufferV3] # Check if we can do a partial read if ( self._partial_decompress @@ -2167,6 +2167,7 @@ def _chunk_getitems( cdatas = {key: value for key, value in zip(ckeys, values) if value is not None} else: partial_read_decode = False + contexts: dict[str, Context] | ConstantMap contexts = {} if not isinstance(self._meta_array, np.ndarray): contexts = ConstantMap(ckeys, constant=Context(meta_array=self._meta_array)) @@ -2319,7 +2320,7 @@ def _process_for_setitem(self, ckey, chunk_selection, value, fields=None): return chunk - def _chunk_key(self, chunk_coords): + def _chunk_key(self, chunk_coords) -> str: if self._version == 3: # _chunk_key() corresponds to data_key(P, i, j, ...) example in the spec # where P = self._key_prefix, i, j, ... = chunk_coords @@ -2536,12 +2537,7 @@ def hexdigest(self, hashname="sha1"): """ checksum = binascii.hexlify(self.digest(hashname=hashname)) - - # This is a bytes object on Python 3 and we want a str. - if not isinstance(checksum, str): - checksum = checksum.decode("utf8") - - return checksum + return checksum.decode("utf8") def __getstate__(self): return { @@ -2559,7 +2555,7 @@ def __getstate__(self): } def __setstate__(self, state): - self.__init__(**state) + self.__init__(**state) # type: ignore[misc] def _synchronized_op(self, f, *args, **kwargs): if self._synchronizer is None: