Skip to content

Commit

Permalink
Check untyped defs in zarr.core
Browse files Browse the repository at this point in the history
  • Loading branch information
dstansby committed Mar 18, 2024
1 parent 51400aa commit 8c58328
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ check_untyped_defs = true
[[tool.mypy.overrides]]
module = [
"zarr.tests.*",
"zarr.core",
"zarr._storage.*"
]
check_untyped_defs = false
Expand Down
20 changes: 8 additions & 12 deletions zarr/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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:
Expand Down

0 comments on commit 8c58328

Please sign in to comment.