Skip to content

Commit dded848

Browse files
d-v-bclaude
andcommitted
fix(core): type coalesced_get as AsyncGenerator
coalesced_get is implemented as an async generator (uses yield) and callers need access to aclose() to drive its finally block deterministically. Declaring the return type as AsyncGenerator instead of AsyncIterator exposes aclose()/asend()/athrow() through the type system, matches the runtime object, and lets consumers (e.g. the consumer-break test) avoid type-ignore escape hatches. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 6aa6f4b commit dded848

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

src/zarr/core/_coalesce.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import TYPE_CHECKING, TypedDict
66

77
if TYPE_CHECKING:
8-
from collections.abc import AsyncIterator, Awaitable, Callable, Iterable, Sequence
8+
from collections.abc import AsyncGenerator, Awaitable, Callable, Iterable, Sequence
99

1010
from zarr.abc.store import ByteRequest
1111
from zarr.core.buffer import Buffer
@@ -37,7 +37,7 @@ async def coalesced_get(
3737
byte_ranges: Iterable[ByteRequest | None],
3838
*,
3939
options: CoalesceOptions,
40-
) -> AsyncIterator[Sequence[tuple[int, Buffer | None]]]:
40+
) -> AsyncGenerator[Sequence[tuple[int, Buffer | None]], None]:
4141
"""Read many byte ranges through ``fetch`` with coalescing and concurrency.
4242
4343
Nearby ranges are merged into a single underlying I/O (subject to

tests/test_coalesce.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ async def fetch(byte_range: ByteRequest | None) -> Buffer | None:
397397
# Break after receiving the first yield.
398398
async for _group in agen:
399399
break
400-
# Make sure the async generator is fully closed so its finally runs.
400+
# Explicitly close the generator so its finally block runs (cancelling
401+
# in-flight tasks) before we make assertions.
401402
await agen.aclose()
402403

403404
# At least one slow fetch was actually running under the semaphore and got

0 commit comments

Comments
 (0)