Skip to content

Commit

Permalink
Fix the return type of Store list methods
Browse files Browse the repository at this point in the history
`None` was added in 0e035fb, let's try to remove it.
  • Loading branch information
DimitriPapadopoulos committed Oct 20, 2024
1 parent d85638a commit 93ff6f2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/zarr/abc/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def supports_listing(self) -> bool:
...

@abstractmethod
async def list(self) -> AsyncGenerator[str, None]:
async def list(self) -> AsyncGenerator[str]:
"""Retrieve all keys in the store.
Returns
Expand All @@ -340,7 +340,7 @@ async def list(self) -> AsyncGenerator[str, None]:
yield ""

@abstractmethod
async def list_prefix(self, prefix: str) -> AsyncGenerator[str, None]:
async def list_prefix(self, prefix: str) -> AsyncGenerator[str]:
"""
Retrieve all keys in the store that begin with a given prefix. Keys are returned with the
common leading prefix removed.
Expand All @@ -356,7 +356,7 @@ async def list_prefix(self, prefix: str) -> AsyncGenerator[str, None]:
yield ""

@abstractmethod
async def list_dir(self, prefix: str) -> AsyncGenerator[str, None]:
async def list_dir(self, prefix: str) -> AsyncGenerator[str]:
"""
Retrieve all keys and prefixes with a given prefix and which do not contain the character
“/” after the given prefix.
Expand Down
6 changes: 3 additions & 3 deletions src/zarr/storage/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,21 +217,21 @@ async def exists(self, key: str) -> bool:
path = self.root / key
return await asyncio.to_thread(path.is_file)

async def list(self) -> AsyncGenerator[str, None]:
async def list(self) -> AsyncGenerator[str]:
# docstring inherited
to_strip = str(self.root) + "/"
for p in list(self.root.rglob("*")):
if p.is_file():
yield str(p).replace(to_strip, "")

async def list_prefix(self, prefix: str) -> AsyncGenerator[str, None]:
async def list_prefix(self, prefix: str) -> AsyncGenerator[str]:
# docstring inherited
to_strip = os.path.join(str(self.root / prefix))
for p in (self.root / prefix).rglob("*"):
if p.is_file():
yield str(p.relative_to(to_strip))

async def list_dir(self, prefix: str) -> AsyncGenerator[str, None]:
async def list_dir(self, prefix: str) -> AsyncGenerator[str]:
# docstring inherited
base = self.root / prefix
to_strip = str(base) + "/"
Expand Down
6 changes: 3 additions & 3 deletions src/zarr/storage/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,19 @@ async def set_partial_values(
with self.log(keys):
return await self._store.set_partial_values(key_start_values=key_start_values)

async def list(self) -> AsyncGenerator[str, None]:
async def list(self) -> AsyncGenerator[str]:
# docstring inherited
with self.log():
async for key in self._store.list():
yield key

async def list_prefix(self, prefix: str) -> AsyncGenerator[str, None]:
async def list_prefix(self, prefix: str) -> AsyncGenerator[str]:
# docstring inherited
with self.log(prefix):
async for key in self._store.list_prefix(prefix=prefix):
yield key

async def list_dir(self, prefix: str) -> AsyncGenerator[str, None]:
async def list_dir(self, prefix: str) -> AsyncGenerator[str]:
# docstring inherited
with self.log(prefix):
async for key in self._store.list_dir(prefix=prefix):
Expand Down
6 changes: 3 additions & 3 deletions src/zarr/storage/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,18 @@ async def set_partial_values(self, key_start_values: Iterable[tuple[str, int, by
# docstring inherited
raise NotImplementedError

async def list(self) -> AsyncGenerator[str, None]:
async def list(self) -> AsyncGenerator[str]:
# docstring inherited
for key in self._store_dict:
yield key

async def list_prefix(self, prefix: str) -> AsyncGenerator[str, None]:
async def list_prefix(self, prefix: str) -> AsyncGenerator[str]:
# docstring inherited
for key in self._store_dict:
if key.startswith(prefix):
yield key.removeprefix(prefix)

async def list_dir(self, prefix: str) -> AsyncGenerator[str, None]:
async def list_dir(self, prefix: str) -> AsyncGenerator[str]:
# docstring inherited
prefix = prefix.rstrip("/")

Expand Down
6 changes: 3 additions & 3 deletions src/zarr/storage/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,13 @@ async def set_partial_values(
# docstring inherited
raise NotImplementedError

async def list(self) -> AsyncGenerator[str, None]:
async def list(self) -> AsyncGenerator[str]:
# docstring inherited
allfiles = await self.fs._find(self.path, detail=False, withdirs=False)
for onefile in (a.replace(self.path + "/", "") for a in allfiles):
yield onefile

async def list_dir(self, prefix: str) -> AsyncGenerator[str, None]:
async def list_dir(self, prefix: str) -> AsyncGenerator[str]:
# docstring inherited
prefix = f"{self.path}/{prefix.rstrip('/')}"
try:
Expand All @@ -296,7 +296,7 @@ async def list_dir(self, prefix: str) -> AsyncGenerator[str, None]:
for onefile in (a.replace(prefix + "/", "") for a in allfiles):
yield onefile.removeprefix(self.path).removeprefix("/")

async def list_prefix(self, prefix: str) -> AsyncGenerator[str, None]:
async def list_prefix(self, prefix: str) -> AsyncGenerator[str]:
# docstring inherited
find_str = f"{self.path}/{prefix}"
for onefile in await self.fs._find(find_str, detail=False, maxdepth=None, withdirs=False):
Expand Down
6 changes: 3 additions & 3 deletions src/zarr/storage/zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,19 @@ async def exists(self, key: str) -> bool:
else:
return True

async def list(self) -> AsyncGenerator[str, None]:
async def list(self) -> AsyncGenerator[str]:
# docstring inherited
with self._lock:
for key in self._zf.namelist():
yield key

async def list_prefix(self, prefix: str) -> AsyncGenerator[str, None]:
async def list_prefix(self, prefix: str) -> AsyncGenerator[str]:
# docstring inherited
async for key in self.list():
if key.startswith(prefix):
yield key.removeprefix(prefix)

async def list_dir(self, prefix: str) -> AsyncGenerator[str, None]:
async def list_dir(self, prefix: str) -> AsyncGenerator[str]:
# docstring inherited
prefix = prefix.rstrip("/")

Expand Down

0 comments on commit 93ff6f2

Please sign in to comment.