Skip to content

Commit 6be2a17

Browse files
Consistent signatures for listdir() and rmdir()
1 parent f0677c2 commit 6be2a17

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

zarr/_storage/store.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
group_meta_key = '.zgroup'
1010
attrs_key = '.zattrs'
1111

12+
Path = Union[str, bytes, None]
13+
1214

1315
class BaseStore(MutableMapping):
1416
"""Abstract base class for store implementations.
@@ -118,11 +120,11 @@ class Store(BaseStore):
118120
119121
"""
120122

121-
def listdir(self, path: str = "") -> List[str]:
123+
def listdir(self, path: Path = None) -> List[str]:
122124
path = normalize_storage_path(path)
123125
return _listdir_from_keys(self, path)
124126

125-
def rmdir(self, path: str = "") -> None:
127+
def rmdir(self, path: Path = None) -> None:
126128
if not self.is_erasable():
127129
raise NotImplementedError(
128130
f'{type(self)} is not erasable, cannot call "rmdir"'
@@ -150,15 +152,7 @@ def _rename_from_keys(store: BaseStore, src_path: str, dst_path: str) -> None:
150152
store[new_key] = store.pop(key)
151153

152154

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-
161-
def _listdir_from_keys(store: BaseStore, path: Optional[str] = None) -> List[str]:
155+
def _listdir_from_keys(store: BaseStore, path: Optional[Path] = None) -> List[str]:
162156
# assume path already normalized
163157
prefix = _path_to_prefix(path)
164158
children = set()
@@ -168,3 +162,11 @@ def _listdir_from_keys(store: BaseStore, path: Optional[str] = None) -> List[str
168162
child = suffix.split('/')[0]
169163
children.add(child)
170164
return sorted(children)
165+
166+
167+
def _rmdir_from_keys(store: Union[BaseStore, MutableMapping], path: Optional[Path] = None) -> None:
168+
# assume path already normalized
169+
prefix = _path_to_prefix(path)
170+
for key in list(store.keys()):
171+
if key.startswith(prefix):
172+
del store[key]

zarr/storage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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: Path = 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)