Skip to content

Commit 519f7ef

Browse files
authored
Fix linting errors (#1226)
* Fix variable possible unbound error * Avoid extra version check This avoids having to check the version twice: once in the "in [2,3]" and also in the if/elif statement. It also fixes linting error of normalize_store being possibly unbound. * Add Optional where necessary to indicate that value could be None
1 parent f2b5585 commit 519f7ef

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

zarr/creation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Optional
12
from warnings import warn
23

34
import numpy as np
@@ -17,7 +18,7 @@
1718

1819

1920
def create(shape, chunks=True, dtype=None, compressor='default',
20-
fill_value=0, order='C', store=None, synchronizer=None,
21+
fill_value: Optional[int] = 0, order='C', store=None, synchronizer=None,
2122
overwrite=False, path=None, chunk_store=None, filters=None,
2223
cache_metadata=True, cache_attrs=True, read_only=False,
2324
object_codec=None, dimension_separator=None, write_empty_chunks=True,

zarr/hierarchy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def __init__(self, store, path=None, read_only=False, chunk_store=None,
157157
raise ContainsArrayError(path)
158158

159159
# initialize metadata
160+
mkey = None
160161
try:
161162
mkey = _prefix_to_group_key(self._store, self._key_prefix)
162163
assert not mkey.endswith("root/.group")
@@ -1277,6 +1278,7 @@ def group(store=None, overwrite=False, chunk_store=None,
12771278

12781279
path = normalize_storage_path(path)
12791280

1281+
requires_init = None
12801282
if zarr_version == 2:
12811283
requires_init = overwrite or not contains_group(store)
12821284
elif zarr_version == 3:

zarr/storage.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ def normalize_store_arg(store: Any, storage_options=None, mode="r", *,
161161
if zarr_version is None:
162162
# default to v2 store for backward compatibility
163163
zarr_version = getattr(store, "_store_version", DEFAULT_ZARR_VERSION)
164-
elif zarr_version not in [2, 3]:
165-
raise ValueError("zarr_version must be either 2 or 3")
166164
if zarr_version == 2:
167165
normalize_store = _normalize_store_arg_v2
168166
elif zarr_version == 3:
169167
from zarr._storage.v3 import _normalize_store_arg_v3
170168
normalize_store = _normalize_store_arg_v3
169+
else:
170+
raise ValueError("zarr_version must be either 2 or 3")
171171
return normalize_store(store, storage_options, mode)
172172

173173

@@ -597,7 +597,7 @@ def init_group(
597597
store: StoreLike,
598598
overwrite: bool = False,
599599
path: Path = None,
600-
chunk_store: StoreLike = None,
600+
chunk_store: Optional[StoreLike] = None,
601601
):
602602
"""Initialize a group store. Note that this is a low-level function and there should be no
603603
need to call this directly from user code.
@@ -644,7 +644,7 @@ def _init_group_metadata(
644644
store: StoreLike,
645645
overwrite: Optional[bool] = False,
646646
path: Optional[str] = None,
647-
chunk_store: StoreLike = None,
647+
chunk_store: Optional[StoreLike] = None,
648648
):
649649

650650
store_version = getattr(store, '_store_version', 2)

0 commit comments

Comments
 (0)