2
2
3
3
import json
4
4
from pathlib import Path
5
- from typing import TYPE_CHECKING , Any , Literal
5
+ from typing import TYPE_CHECKING , Any , Literal , Self
6
6
7
7
from zarr .abc .store import ByteRequest , Store
8
8
from zarr .core .buffer import Buffer , default_buffer_prototype
@@ -48,9 +48,7 @@ def read_only(self) -> bool:
48
48
return self .store .read_only
49
49
50
50
@classmethod
51
- async def open (
52
- cls , store : Store , path : str , mode : AccessModeLiteral | None = None
53
- ) -> StorePath :
51
+ async def open (cls , store : Store , path : str , mode : AccessModeLiteral | None = None ) -> Self :
54
52
"""
55
53
Open StorePath based on the provided mode.
56
54
@@ -67,6 +65,9 @@ async def open(
67
65
------
68
66
FileExistsError
69
67
If the mode is 'w-' and the store path already exists.
68
+ ValueError
69
+ If the mode is not "r" and the store is read-only, or
70
+ if the mode is "r" and the store is not read-only.
70
71
"""
71
72
72
73
await store ._ensure_open ()
@@ -78,6 +79,8 @@ async def open(
78
79
79
80
if store .read_only and mode != "r" :
80
81
raise ValueError (f"Store is read-only but mode is '{ mode } '" )
82
+ if not store .read_only and mode == "r" :
83
+ raise ValueError (f"Store is not read-only but mode is '{ mode } '" )
81
84
82
85
match mode :
83
86
case "w-" :
0 commit comments