Skip to content

Commit edaa5d0

Browse files
fix(storage): MemoryStore.list_prefix uses directory-boundary semantics
1 parent 3a2ce2f commit edaa5d0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/zarr/storage/_memory.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,15 @@ async def list(self) -> AsyncIterator[str]:
193193

194194
async def list_prefix(self, prefix: str) -> AsyncIterator[str]:
195195
# docstring inherited
196-
# note: we materialize all dict keys into a list here so we can mutate the dict in-place (e.g. in delete_prefix)
196+
# Normalise prefix to use directory-boundary semantics consistent with LocalStore:
197+
# list_prefix("0") must match "0/zarr.json" but NOT "0_c/zarr.json".
198+
# We strip any trailing "/" then re-add it so the startswith check only
199+
# matches at a path separator, not mid-name.
200+
# note: we materialise all dict keys into a list here so we can mutate
201+
# the dict in-place (e.g. in delete_prefix)
202+
prefix = prefix.rstrip("/")
203+
if prefix:
204+
prefix = prefix + "/"
197205
for key in list(self._store_dict):
198206
if key.startswith(prefix):
199207
yield key

0 commit comments

Comments
 (0)