Skip to content

Commit 1f8f360

Browse files
committed
use as_posix for str and for listdir
1 parent 4c3081c commit 1f8f360

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

src/zarr/storage/local.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def with_mode(self, mode: AccessModeLiteral) -> Self:
132132
return type(self)(root=self.root, mode=mode)
133133

134134
def __str__(self) -> str:
135-
return f"file://{self.root}"
135+
return f"file://{self.root.as_posix()}"
136136

137137
def __repr__(self) -> str:
138138
return f"LocalStore({str(self)!r})"
@@ -236,11 +236,9 @@ async def list_prefix(self, prefix: str) -> AsyncGenerator[str, None]:
236236
async def list_dir(self, prefix: str) -> AsyncGenerator[str, None]:
237237
# docstring inherited
238238
base = self.root / prefix
239-
to_strip = str(base) + "/"
240-
241239
try:
242240
key_iter = base.iterdir()
243241
for key in key_iter:
244-
yield key.as_posix().replace(to_strip, "")
242+
yield key.relative_to(base).as_posix()
245243
except (FileNotFoundError, NotADirectoryError):
246244
pass

tests/test_store/test_local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def store_kwargs(self, tmpdir) -> dict[str, str]:
3131
return {"root": str(tmpdir), "mode": "r+"}
3232

3333
def test_store_repr(self, store: LocalStore) -> None:
34-
assert str(store) == f"file://{store.root!s}"
34+
assert str(store) == f"file://{store.root.as_posix()!s}"
3535

3636
def test_store_supports_writes(self, store: LocalStore) -> None:
3737
assert store.supports_writes

0 commit comments

Comments
 (0)