22
33import json
44from pathlib import Path
5- from typing import TYPE_CHECKING , Any , Literal
5+ from typing import TYPE_CHECKING , Any , Literal , Self
66
77from zarr .abc .store import ByteRequest , Store
88from zarr .core .buffer import Buffer , default_buffer_prototype
@@ -48,9 +48,7 @@ def read_only(self) -> bool:
4848 return self .store .read_only
4949
5050 @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 :
5452 """
5553 Open StorePath based on the provided mode.
5654
@@ -67,6 +65,9 @@ async def open(
6765 ------
6866 FileExistsError
6967 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.
7071 """
7172
7273 await store ._ensure_open ()
@@ -78,6 +79,8 @@ async def open(
7879
7980 if store .read_only and mode != "r" :
8081 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 } '" )
8184
8285 match mode :
8386 case "w-" :
0 commit comments