Skip to content

Commit 850b9cd

Browse files
d-v-bclaude
andcommitted
refactor(core): drop dead invariant checks in merged-group path
After the input split at the top of coalesced_get, merged groups only ever contain RangeByteRequest members. Replace the per-element isinstance filters (and the defensive ``else 0`` sort-key branch) with a single assertion at the top of the merged-group block and direct attribute access. Also remove the unreachable ``if total == 0: return`` guard (``indexed`` is non-empty by construction once we pass the earlier guard). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 913928c commit 850b9cd

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

src/zarr/core/_coalesce.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ async def coalesced_get(
118118
work_items.extend([(idx, single)] for idx, single in uncoalescable)
119119

120120
total = len(work_items)
121-
if total == 0:
122-
return
123121

124122
# Completion queue entries are either ("ok", payload), ("missing", None),
125123
# or ("error", exception). Kept as Any internally to avoid dragging
@@ -142,22 +140,19 @@ async def run_one(members: list[tuple[int, ByteRequest | None]]) -> None:
142140
await completion_queue.put(("ok", ((idx, buf),)))
143141
return
144142
# Merged group path: all members are RangeByteRequest.
145-
starts = [r.start for _, r in members if isinstance(r, RangeByteRequest)]
146-
ends = [r.end for _, r in members if isinstance(r, RangeByteRequest)]
143+
assert all(isinstance(r, RangeByteRequest) for _, r in members)
144+
starts = [r.start for _, r in members] # type: ignore[union-attr]
145+
ends = [r.end for _, r in members] # type: ignore[union-attr]
147146
group_start = min(starts)
148147
group_end = max(ends)
149148
big = await fetch(RangeByteRequest(group_start, group_end))
150149
if big is None:
151150
await completion_queue.put(("missing", None))
152151
return
153-
ordered = sorted(
154-
members,
155-
key=lambda pair: pair[1].start if isinstance(pair[1], RangeByteRequest) else 0,
156-
)
152+
ordered = sorted(members, key=lambda pair: pair[1].start) # type: ignore[union-attr]
157153
sliced: list[tuple[int, Buffer | None]] = []
158154
for idx, r in ordered:
159-
assert isinstance(r, RangeByteRequest)
160-
sliced.append((idx, big[r.start - group_start : r.end - group_start]))
155+
sliced.append((idx, big[r.start - group_start : r.end - group_start])) # type: ignore[union-attr]
161156
await completion_queue.put(("ok", tuple(sliced)))
162157
except asyncio.CancelledError:
163158
# Cancellation is expected when we stop scheduling on a missing key.

0 commit comments

Comments
 (0)