diff --git a/zarr/_storage/store.py b/zarr/_storage/store.py index 6f5bf78e28..a473424772 100644 --- a/zarr/_storage/store.py +++ b/zarr/_storage/store.py @@ -118,11 +118,11 @@ class Store(BaseStore): """ - def listdir(self, path: str = "") -> List[str]: + def listdir(self, path: str = None) -> List[str]: path = normalize_storage_path(path) return _listdir_from_keys(self, path) - def rmdir(self, path: str = "") -> None: + def rmdir(self, path: str = None) -> None: if not self.is_erasable(): raise NotImplementedError( 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: store[new_key] = store.pop(key) -def _rmdir_from_keys(store: Union[BaseStore, MutableMapping], path: Optional[str] = None) -> None: - # assume path already normalized - prefix = _path_to_prefix(path) - for key in list(store.keys()): - if key.startswith(prefix): - del store[key] - - def _listdir_from_keys(store: BaseStore, path: Optional[str] = None) -> List[str]: # assume path already normalized prefix = _path_to_prefix(path) @@ -168,3 +160,11 @@ def _listdir_from_keys(store: BaseStore, path: Optional[str] = None) -> List[str child = suffix.split('/')[0] children.add(child) return sorted(children) + + +def _rmdir_from_keys(store: Union[BaseStore, MutableMapping], path: Optional[str] = None) -> None: + # assume path already normalized + prefix = _path_to_prefix(path) + for key in list(store.keys()): + if key.startswith(prefix): + del store[key] diff --git a/zarr/storage.py b/zarr/storage.py index b5da03701c..951bb1ffc3 100644 --- a/zarr/storage.py +++ b/zarr/storage.py @@ -128,7 +128,7 @@ def normalize_store_arg(store: Any, clobber=False, storage_options=None, mode="w return store -def rmdir(store: StoreLike, path: Path = None): +def rmdir(store: StoreLike, path: str = None): """Remove all items under the given path. If `store` provides a `rmdir` method, this will be called, otherwise will fall back to implementation via the `Store` interface.""" @@ -155,7 +155,7 @@ def rename(store: BaseStore, src_path: Path, dst_path: Path): _rename_from_keys(store, src_path, dst_path) -def listdir(store: BaseStore, path: Path = None): +def listdir(store: BaseStore, path: str = None): """Obtain a directory listing for the given path. If `store` provides a `listdir` method, this will be called, otherwise will fall back to implementation via the `MutableMapping` interface.""" @@ -694,7 +694,7 @@ def __iter__(self): def __len__(self) -> int: return sum(1 for _ in self.keys()) - def listdir(self, path: Path = None) -> List[str]: + def listdir(self, path: str = None) -> List[str]: path = normalize_storage_path(path) if path: try: @@ -718,7 +718,7 @@ def rename(self, src_path: Path, dst_path: Path): dst_parent[dst_key] = src_parent.pop(src_key) - def rmdir(self, path: Path = None): + def rmdir(self, path: str = None): path = normalize_storage_path(path) if path: try: @@ -2157,7 +2157,7 @@ def _keys(self): self._keys_cache = list(self._store.keys()) return self._keys_cache - def listdir(self, path: Path = None): + def listdir(self, path: str = None) -> List[str]: with self._mutex: try: return self._listdir_cache[path] @@ -2682,5 +2682,5 @@ def __setitem__(self, key, value): def getsize(self, path): return getsize(self.meta_store, path) - def listdir(self, path): + def listdir(self, path=None): return listdir(self.meta_store, path)