Skip to content

Commit 86ea815

Browse files
Consistent signatures for listdir() and rmdir()
1 parent f0677c2 commit 86ea815

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

zarr/_storage/store.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ class Store(BaseStore):
118118
119119
"""
120120

121-
def listdir(self, path: str = "") -> List[str]:
121+
def listdir(self, path: str = None) -> List[str]:
122122
path = normalize_storage_path(path)
123123
return _listdir_from_keys(self, path)
124124

125-
def rmdir(self, path: str = "") -> None:
125+
def rmdir(self, path: str = None) -> None:
126126
if not self.is_erasable():
127127
raise NotImplementedError(
128128
f'{type(self)} is not erasable, cannot call "rmdir"'
@@ -150,14 +150,6 @@ def _rename_from_keys(store: BaseStore, src_path: str, dst_path: str) -> None:
150150
store[new_key] = store.pop(key)
151151

152152

153-
def _rmdir_from_keys(store: Union[BaseStore, MutableMapping], path: Optional[str] = None) -> None:
154-
# assume path already normalized
155-
prefix = _path_to_prefix(path)
156-
for key in list(store.keys()):
157-
if key.startswith(prefix):
158-
del store[key]
159-
160-
161153
def _listdir_from_keys(store: BaseStore, path: Optional[str] = None) -> List[str]:
162154
# assume path already normalized
163155
prefix = _path_to_prefix(path)
@@ -168,3 +160,11 @@ def _listdir_from_keys(store: BaseStore, path: Optional[str] = None) -> List[str
168160
child = suffix.split('/')[0]
169161
children.add(child)
170162
return sorted(children)
163+
164+
165+
def _rmdir_from_keys(store: Union[BaseStore, MutableMapping], path: Optional[str] = None) -> None:
166+
# assume path already normalized
167+
prefix = _path_to_prefix(path)
168+
for key in list(store.keys()):
169+
if key.startswith(prefix):
170+
del store[key]

zarr/storage.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def normalize_store_arg(store: Any, clobber=False, storage_options=None, mode="w
128128
return store
129129

130130

131-
def rmdir(store: StoreLike, path: Path = None):
131+
def rmdir(store: StoreLike, path: str = None):
132132
"""Remove all items under the given path. If `store` provides a `rmdir` method,
133133
this will be called, otherwise will fall back to implementation via the
134134
`Store` interface."""
@@ -155,7 +155,7 @@ def rename(store: BaseStore, src_path: Path, dst_path: Path):
155155
_rename_from_keys(store, src_path, dst_path)
156156

157157

158-
def listdir(store: BaseStore, path: Path = None):
158+
def listdir(store: BaseStore, path: str = None):
159159
"""Obtain a directory listing for the given path. If `store` provides a `listdir`
160160
method, this will be called, otherwise will fall back to implementation via the
161161
`MutableMapping` interface."""
@@ -694,7 +694,7 @@ def __iter__(self):
694694
def __len__(self) -> int:
695695
return sum(1 for _ in self.keys())
696696

697-
def listdir(self, path: Path = None) -> List[str]:
697+
def listdir(self, path: str = None) -> List[str]:
698698
path = normalize_storage_path(path)
699699
if path:
700700
try:
@@ -718,7 +718,7 @@ def rename(self, src_path: Path, dst_path: Path):
718718

719719
dst_parent[dst_key] = src_parent.pop(src_key)
720720

721-
def rmdir(self, path: Path = None):
721+
def rmdir(self, path: str = None):
722722
path = normalize_storage_path(path)
723723
if path:
724724
try:
@@ -2157,7 +2157,7 @@ def _keys(self):
21572157
self._keys_cache = list(self._store.keys())
21582158
return self._keys_cache
21592159

2160-
def listdir(self, path: Path = None):
2160+
def listdir(self, path: str = None) -> List[str]:
21612161
with self._mutex:
21622162
try:
21632163
return self._listdir_cache[path]
@@ -2682,5 +2682,5 @@ def __setitem__(self, key, value):
26822682
def getsize(self, path):
26832683
return getsize(self.meta_store, path)
26842684

2685-
def listdir(self, path):
2685+
def listdir(self, path=None):
26862686
return listdir(self.meta_store, path)

0 commit comments

Comments
 (0)