Skip to content

Commit 113e9cd

Browse files
AsyncIterator
1 parent 680142f commit 113e9cd

File tree

6 files changed

+26
-26
lines changed

6 files changed

+26
-26
lines changed

src/zarr/abc/store.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import TYPE_CHECKING, NamedTuple, Protocol, runtime_checkable
77

88
if TYPE_CHECKING:
9-
from collections.abc import AsyncGenerator, Iterable
9+
from collections.abc import AsyncGenerator, AsyncIterator, Iterable
1010
from types import TracebackType
1111
from typing import Any, Self, TypeAlias
1212

@@ -329,16 +329,16 @@ def supports_listing(self) -> bool:
329329
...
330330

331331
@abstractmethod
332-
def list(self) -> AsyncGenerator[str]:
332+
def list(self) -> AsyncIterator[str]:
333333
"""Retrieve all keys in the store.
334334
335335
Returns
336336
-------
337-
AsyncGenerator[str, None]
337+
AsyncIterator[str]
338338
"""
339339

340340
@abstractmethod
341-
def list_prefix(self, prefix: str) -> AsyncGenerator[str]:
341+
def list_prefix(self, prefix: str) -> AsyncIterator[str]:
342342
"""
343343
Retrieve all keys in the store that begin with a given prefix. Keys are returned relative
344344
to the root of the store.
@@ -349,11 +349,11 @@ def list_prefix(self, prefix: str) -> AsyncGenerator[str]:
349349
350350
Returns
351351
-------
352-
AsyncGenerator[str, None]
352+
AsyncIterator[str]
353353
"""
354354

355355
@abstractmethod
356-
def list_dir(self, prefix: str) -> AsyncGenerator[str]:
356+
def list_dir(self, prefix: str) -> AsyncIterator[str]:
357357
"""
358358
Retrieve all keys and prefixes with a given prefix and which do not contain the character
359359
“/” after the given prefix.
@@ -364,7 +364,7 @@ def list_dir(self, prefix: str) -> AsyncGenerator[str]:
364364
365365
Returns
366366
-------
367-
AsyncGenerator[str, None]
367+
AsyncIterator[str]
368368
"""
369369

370370
async def delete_dir(self, prefix: str) -> None:

src/zarr/storage/local.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,22 +217,22 @@ async def exists(self, key: str) -> bool:
217217
path = self.root / key
218218
return await asyncio.to_thread(path.is_file)
219219

220-
async def list(self) -> AsyncGenerator[str]:
220+
async def list(self) -> AsyncIterator[str]:
221221
# docstring inherited
222222
to_strip = self.root.as_posix() + "/"
223223
for p in list(self.root.rglob("*")):
224224
if p.is_file():
225225
yield p.as_posix().replace(to_strip, "")
226226

227-
async def list_prefix(self, prefix: str) -> AsyncGenerator[str]:
227+
async def list_prefix(self, prefix: str) -> AsyncIterator[str]:
228228
# docstring inherited
229229
to_strip = self.root.as_posix() + "/"
230230
prefix = prefix.rstrip("/")
231231
for p in (self.root / prefix).rglob("*"):
232232
if p.is_file():
233233
yield p.as_posix().replace(to_strip, "")
234234

235-
async def list_dir(self, prefix: str) -> AsyncGenerator[str]:
235+
async def list_dir(self, prefix: str) -> AsyncIterator[str]:
236236
# docstring inherited
237237
base = self.root / prefix
238238
try:

src/zarr/storage/logging.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from zarr.abc.store import AccessMode, ByteRangeRequest, Store
1111

1212
if TYPE_CHECKING:
13-
from collections.abc import AsyncGenerator, Generator, Iterable
13+
from collections.abc import AsyncIterator, Generator, Iterable
1414

1515
from zarr.core.buffer import Buffer, BufferPrototype
1616
from zarr.core.common import AccessModeLiteral
@@ -204,19 +204,19 @@ async def set_partial_values(
204204
with self.log(keys):
205205
return await self._store.set_partial_values(key_start_values=key_start_values)
206206

207-
async def list(self) -> AsyncGenerator[str]:
207+
async def list(self) -> AsyncIterator[str]:
208208
# docstring inherited
209209
with self.log():
210210
async for key in self._store.list():
211211
yield key
212212

213-
async def list_prefix(self, prefix: str) -> AsyncGenerator[str]:
213+
async def list_prefix(self, prefix: str) -> AsyncIterator[str]:
214214
# docstring inherited
215215
with self.log(prefix):
216216
async for key in self._store.list_prefix(prefix=prefix):
217217
yield key
218218

219-
async def list_dir(self, prefix: str) -> AsyncGenerator[str]:
219+
async def list_dir(self, prefix: str) -> AsyncIterator[str]:
220220
# docstring inherited
221221
with self.log(prefix):
222222
async for key in self._store.list_dir(prefix=prefix):

src/zarr/storage/memory.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from zarr.storage._utils import _normalize_interval_index
1010

1111
if TYPE_CHECKING:
12-
from collections.abc import AsyncGenerator, Iterable, MutableMapping
12+
from collections.abc import AsyncIterator, Iterable, MutableMapping
1313

1414
from zarr.core.buffer import BufferPrototype
1515
from zarr.core.common import AccessModeLiteral
@@ -147,19 +147,19 @@ async def set_partial_values(self, key_start_values: Iterable[tuple[str, int, by
147147
# docstring inherited
148148
raise NotImplementedError
149149

150-
async def list(self) -> AsyncGenerator[str]:
150+
async def list(self) -> AsyncIterator[str]:
151151
# docstring inherited
152152
for key in self._store_dict:
153153
yield key
154154

155-
async def list_prefix(self, prefix: str) -> AsyncGenerator[str]:
155+
async def list_prefix(self, prefix: str) -> AsyncIterator[str]:
156156
# docstring inherited
157157
# note: we materialize all dict keys into a list here so we can mutate the dict in-place (e.g. in delete_prefix)
158158
for key in list(self._store_dict):
159159
if key.startswith(prefix):
160160
yield key
161161

162-
async def list_dir(self, prefix: str) -> AsyncGenerator[str]:
162+
async def list_dir(self, prefix: str) -> AsyncIterator[str]:
163163
# docstring inherited
164164
prefix = prefix.rstrip("/")
165165

src/zarr/storage/remote.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from zarr.storage.common import _dereference_path
88

99
if TYPE_CHECKING:
10-
from collections.abc import AsyncGenerator, Iterable
10+
from collections.abc import AsyncIterator, Iterable
1111

1212
from fsspec.asyn import AsyncFileSystem
1313

@@ -322,13 +322,13 @@ async def set_partial_values(
322322
# docstring inherited
323323
raise NotImplementedError
324324

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

331-
async def list_dir(self, prefix: str) -> AsyncGenerator[str]:
331+
async def list_dir(self, prefix: str) -> AsyncIterator[str]:
332332
# docstring inherited
333333
prefix = f"{self.path}/{prefix.rstrip('/')}"
334334
try:
@@ -338,7 +338,7 @@ async def list_dir(self, prefix: str) -> AsyncGenerator[str]:
338338
for onefile in (a.replace(prefix + "/", "") for a in allfiles):
339339
yield onefile.removeprefix(self.path).removeprefix("/")
340340

341-
async def list_prefix(self, prefix: str) -> AsyncGenerator[str]:
341+
async def list_prefix(self, prefix: str) -> AsyncIterator[str]:
342342
# docstring inherited
343343
for onefile in await self.fs._find(
344344
f"{self.path}/{prefix}", detail=False, maxdepth=None, withdirs=False

src/zarr/storage/zip.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from zarr.core.buffer import Buffer, BufferPrototype
1212

1313
if TYPE_CHECKING:
14-
from collections.abc import AsyncGenerator, Iterable
14+
from collections.abc import AsyncIterator, Iterable
1515

1616
ZipStoreAccessModeLiteral = Literal["r", "w", "a"]
1717

@@ -234,19 +234,19 @@ async def exists(self, key: str) -> bool:
234234
else:
235235
return True
236236

237-
async def list(self) -> AsyncGenerator[str]:
237+
async def list(self) -> AsyncIterator[str]:
238238
# docstring inherited
239239
with self._lock:
240240
for key in self._zf.namelist():
241241
yield key
242242

243-
async def list_prefix(self, prefix: str) -> AsyncGenerator[str]:
243+
async def list_prefix(self, prefix: str) -> AsyncIterator[str]:
244244
# docstring inherited
245245
async for key in self.list():
246246
if key.startswith(prefix):
247247
yield key
248248

249-
async def list_dir(self, prefix: str) -> AsyncGenerator[str]:
249+
async def list_dir(self, prefix: str) -> AsyncIterator[str]:
250250
# docstring inherited
251251
prefix = prefix.rstrip("/")
252252

0 commit comments

Comments
 (0)