|
12 | 12 | from zarr.core.common import concurrent_map |
13 | 13 |
|
14 | 14 | if TYPE_CHECKING: |
15 | | - from collections.abc import AsyncGenerator, Iterable |
| 15 | + from collections.abc import AsyncIterator, Iterable |
16 | 16 |
|
17 | 17 | from zarr.core.buffer import BufferPrototype |
18 | 18 | from zarr.core.common import AccessModeLiteral |
@@ -217,28 +217,27 @@ async def exists(self, key: str) -> bool: |
217 | 217 | path = self.root / key |
218 | 218 | return await asyncio.to_thread(path.is_file) |
219 | 219 |
|
220 | | - async def list(self) -> AsyncGenerator[str, None]: |
| 220 | + async def list(self) -> AsyncIterator[str]: |
221 | 221 | # docstring inherited |
222 | | - to_strip = str(self.root) + "/" |
223 | | - for p in list(self.root.rglob("*")): |
| 222 | + to_strip = f"{self.root}/" |
| 223 | + for p in await asyncio.to_thread(self.root.rglob, "*") |
224 | 224 | if p.is_file(): |
225 | 225 | yield str(p).replace(to_strip, "") |
226 | 226 |
|
227 | | - async def list_prefix(self, prefix: str) -> AsyncGenerator[str, None]: |
| 227 | + async def list_prefix(self, prefix: str) -> AsyncIterator[str]: |
228 | 228 | # docstring inherited |
229 | 229 | to_strip = os.path.join(str(self.root / prefix)) |
230 | | - for p in (self.root / prefix).rglob("*"): |
| 230 | + for p in await asyncio.to_thread((self.root / prefix).rglob, "*"): |
231 | 231 | if p.is_file(): |
232 | 232 | yield str(p.relative_to(to_strip)) |
233 | 233 |
|
234 | | - async def list_dir(self, prefix: str) -> AsyncGenerator[str, None]: |
| 234 | + async def list_dir(self, prefix: str) -> AsyncIterator[str]: |
235 | 235 | # docstring inherited |
236 | 236 | base = self.root / prefix |
237 | | - to_strip = str(base) + "/" |
| 237 | + to_strip = f"{base}/" |
238 | 238 |
|
239 | 239 | try: |
240 | | - key_iter = base.iterdir() |
241 | | - for key in key_iter: |
| 240 | + for key in await asyncio.to_thread(base.iterdir): |
242 | 241 | yield str(key).replace(to_strip, "") |
243 | 242 | except (FileNotFoundError, NotADirectoryError): |
244 | 243 | pass |
0 commit comments