2020
2121
2222class AccessMode (NamedTuple ):
23+ """Access mode flags."""
24+
2325 str : AccessModeLiteral
2426 readonly : bool
2527 overwrite : bool
@@ -28,6 +30,24 @@ class AccessMode(NamedTuple):
2830
2931 @classmethod
3032 def from_literal (cls , mode : AccessModeLiteral ) -> Self :
33+ """
34+ Create an AccessMode instance from a literal.
35+
36+ Parameters
37+ ----------
38+ mode : AccessModeLiteral
39+ One of 'r', 'r+', 'w', 'w-', 'a'.
40+
41+ Returns
42+ -------
43+ AccessMode
44+ The created instance.
45+
46+ Raises
47+ ------
48+ ValueError
49+ If mode is not one of 'r', 'r+', 'w', 'w-', 'a'.
50+ """
3151 if mode in ("r" , "r+" , "a" , "w" , "w-" ):
3252 return cls (
3353 str = mode ,
@@ -40,6 +60,10 @@ def from_literal(cls, mode: AccessModeLiteral) -> Self:
4060
4161
4262class Store (ABC ):
63+ """
64+ Abstract base class for Zarr stores.
65+ """
66+
4367 _mode : AccessMode
4468 _is_open : bool
4569
@@ -49,6 +73,21 @@ def __init__(self, *args: Any, mode: AccessModeLiteral = "r", **kwargs: Any) ->
4973
5074 @classmethod
5175 async def open (cls , * args : Any , ** kwargs : Any ) -> Self :
76+ """
77+ Create and open the store.
78+
79+ Parameters
80+ ----------
81+ *args : Any
82+ Positional arguments to pass to the store constructor.
83+ **kwargs : Any
84+ Keyword arguments to pass to the store constructor.
85+
86+ Returns
87+ -------
88+ Store
89+ The opened store instance.
90+ """
5291 store = cls (* args , ** kwargs )
5392 await store ._open ()
5493 return store
@@ -67,6 +106,20 @@ def __exit__(
67106 self .close ()
68107
69108 async def _open (self ) -> None :
109+ """
110+ Open the store.
111+
112+ Raises
113+ ------
114+ ValueError
115+ If the store is already open.
116+ FileExistsError
117+ If ``mode='w-'`` and the store already exists.
118+
119+ Notes
120+ -----
121+ * When ``mode='w'`` and the store already exists, it will be cleared.
122+ """
70123 if self ._is_open :
71124 raise ValueError ("store is already open" )
72125 if self .mode .str == "w" :
@@ -76,14 +129,30 @@ async def _open(self) -> None:
76129 self ._is_open = True
77130
78131 async def _ensure_open (self ) -> None :
132+ """Open the store if it is not already open."""
79133 if not self ._is_open :
80134 await self ._open ()
81135
82136 @abstractmethod
83- async def empty (self ) -> bool : ...
137+ async def empty (self ) -> bool :
138+ """
139+ Check if the store is empty.
140+
141+ Returns
142+ -------
143+ bool
144+ True if the store is empty, False otherwise.
145+ """
146+ ...
84147
85148 @abstractmethod
86- async def clear (self ) -> None : ...
149+ async def clear (self ) -> None :
150+ """
151+ Clear the store.
152+
153+ Remove all keys and values from the store.
154+ """
155+ ...
87156
88157 @abstractmethod
89158 def with_mode (self , mode : AccessModeLiteral ) -> Self :
@@ -116,6 +185,7 @@ def mode(self) -> AccessMode:
116185 return self ._mode
117186
118187 def _check_writable (self ) -> None :
188+ """Raise an exception if the store is not writable."""
119189 if self .mode .readonly :
120190 raise ValueError ("store mode does not support writing" )
121191
@@ -199,7 +269,7 @@ async def set_if_not_exists(self, key: str, value: Buffer) -> None:
199269 Store a key to ``value`` if the key is not already present.
200270
201271 Parameters
202- -----------
272+ ----------
203273 key : str
204274 value : Buffer
205275 """
@@ -339,6 +409,17 @@ async def set_if_not_exists(self, default: Buffer) -> None: ...
339409
340410
341411async def set_or_delete (byte_setter : ByteSetter , value : Buffer | None ) -> None :
412+ """Set or delete a value in a byte setter
413+
414+ Parameters
415+ ----------
416+ byte_setter : ByteSetter
417+ value : Buffer | None
418+
419+ Notes
420+ -----
421+ If value is None, the key will be deleted.
422+ """
342423 if value is None :
343424 await byte_setter .delete ()
344425 else :
0 commit comments