Skip to content

Commit 9804446

Browse files
committed
readonly -> read_only
1 parent 2296c3f commit 9804446

File tree

19 files changed

+97
-89
lines changed

19 files changed

+97
-89
lines changed

src/zarr/abc/store.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ class Store(ABC):
2323
Abstract base class for Zarr stores.
2424
"""
2525

26-
_readonly: bool
26+
_read_only: bool
2727
_is_open: bool
2828

29-
def __init__(self, *, readonly: bool = False) -> None:
29+
def __init__(self, *, read_only: bool = False) -> None:
3030
self._is_open = False
31-
self._readonly = readonly
31+
self._read_only = read_only
3232

3333
@classmethod
3434
async def open(cls, *args: Any, **kwargs: Any) -> Self:
@@ -113,13 +113,13 @@ async def clear(self) -> None:
113113
await self.delete(key)
114114

115115
@property
116-
def readonly(self) -> bool:
116+
def read_only(self) -> bool:
117117
"""Is the store read-only?"""
118-
return self._readonly
118+
return self._read_only
119119

120120
def _check_writable(self) -> None:
121121
"""Raise an exception if the store is not writable."""
122-
if self.readonly:
122+
if self.read_only:
123123
raise ValueError("store was opened in read-only mode and does not support writing")
124124

125125
@abstractmethod

src/zarr/api/asynchronous.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ async def open_array(
10901090
try:
10911091
return await AsyncArray.open(store_path, zarr_format=zarr_format)
10921092
except FileNotFoundError:
1093-
if not store_path.readonly:
1093+
if not store_path.read_only:
10941094
return await create(
10951095
store=store_path,
10961096
zarr_format=zarr_format or _default_zarr_version(),

src/zarr/core/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ def read_only(self) -> bool:
796796
True if the array is read-only
797797
"""
798798
# Backwards compatibility for 2.x
799-
return self.store_path.readonly
799+
return self.store_path.read_only
800800

801801
@property
802802
def path(self) -> str:

src/zarr/core/group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ def store(self) -> Store:
880880
@property
881881
def read_only(self) -> bool:
882882
# Backwards compatibility for 2.x
883-
return self.store_path.readonly
883+
return self.store_path.read_only
884884

885885
@property
886886
def synchronizer(self) -> None:

src/zarr/storage/common.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def __init__(self, store: Store, path: str = "") -> None:
4646
self.path = path
4747

4848
@property
49-
def readonly(self) -> bool:
50-
return self.store.readonly
49+
def read_only(self) -> bool:
50+
return self.store.read_only
5151

5252
@classmethod
5353
async def open(
@@ -78,7 +78,7 @@ async def open(
7878
if mode is None:
7979
return self
8080

81-
if store.readonly and mode != "r":
81+
if store.read_only and mode != "r":
8282
raise ValueError(f"Store is read-only but mode is '{mode}'")
8383

8484
match mode:
@@ -290,32 +290,32 @@ async def make_store_path(
290290

291291
used_storage_options = False
292292
path_normalized = normalize_path(path)
293-
assert mode in (None, "r", "r+", "a", "w", "w-")
294293
if isinstance(store_like, StorePath):
295294
result = store_like / path_normalized
296295
else:
296+
assert mode in (None, "r", "r+", "a", "w", "w-")
297297
# if mode 'r' was provided, we'll open any new stores as read-only
298-
_readonly = mode == "r"
298+
_read_only = mode == "r"
299299
if isinstance(store_like, Store):
300300
store = store_like
301301
elif store_like is None:
302-
store = await MemoryStore.open(readonly=_readonly)
302+
store = await MemoryStore.open(read_only=_read_only)
303303
elif isinstance(store_like, Path):
304-
store = await LocalStore.open(root=store_like, readonly=_readonly)
304+
store = await LocalStore.open(root=store_like, read_only=_read_only)
305305
elif isinstance(store_like, str):
306306
storage_options = storage_options or {}
307307

308308
if _is_fsspec_uri(store_like):
309309
used_storage_options = True
310310
store = RemoteStore.from_url(
311-
store_like, storage_options=storage_options, readonly=_readonly
311+
store_like, storage_options=storage_options, read_only=_read_only
312312
)
313313
else:
314-
store = await LocalStore.open(root=Path(store_like), readonly=_readonly)
314+
store = await LocalStore.open(root=Path(store_like), read_only=_read_only)
315315
elif isinstance(store_like, dict):
316316
# We deliberate only consider dict[str, Buffer] here, and not arbitrary mutable mappings.
317317
# By only allowing dictionaries, which are in-memory, we know that MemoryStore appropriate.
318-
store = await MemoryStore.open(store_dict=store_like, readonly=_readonly)
318+
store = await MemoryStore.open(store_dict=store_like, read_only=_read_only)
319319
else:
320320
msg = f"Unsupported type for store_like: '{type(store_like).__name__}'" # type: ignore[unreachable]
321321
raise TypeError(msg)

src/zarr/storage/local.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class LocalStore(Store):
7272
----------
7373
root : str or Path
7474
Directory to use as root of store.
75-
readonly : bool
75+
read_only : bool
7676
Whether the store is read-only
7777
7878
Attributes
@@ -91,8 +91,8 @@ class LocalStore(Store):
9191

9292
root: Path
9393

94-
def __init__(self, root: Path | str, *, readonly: bool = False) -> None:
95-
super().__init__(readonly=readonly)
94+
def __init__(self, root: Path | str, *, read_only: bool = False) -> None:
95+
super().__init__(read_only=read_only)
9696
if isinstance(root, str):
9797
root = Path(root)
9898
if not isinstance(root, Path):
@@ -102,7 +102,7 @@ def __init__(self, root: Path | str, *, readonly: bool = False) -> None:
102102
self.root = root
103103

104104
async def _open(self) -> None:
105-
if not self.readonly:
105+
if not self.read_only:
106106
self.root.mkdir(parents=True, exist_ok=True)
107107
return await super()._open()
108108

src/zarr/storage/logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ def supports_listing(self) -> bool:
113113
return self._store.supports_listing
114114

115115
@property
116-
def readonly(self) -> bool:
116+
def read_only(self) -> bool:
117117
with self.log():
118-
return self._store.readonly
118+
return self._store.read_only
119119

120120
@property
121121
def _is_open(self) -> bool:

src/zarr/storage/memory.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class MemoryStore(Store):
2525
----------
2626
store_dict : dict
2727
Initial data
28-
readonly : readonly
28+
read_only : bool
2929
Whether the store is read-only
3030
3131
Attributes
@@ -47,9 +47,9 @@ def __init__(
4747
self,
4848
store_dict: MutableMapping[str, Buffer] | None = None,
4949
*,
50-
readonly: bool = False,
50+
read_only: bool = False,
5151
) -> None:
52-
super().__init__(readonly=readonly)
52+
super().__init__(read_only=read_only)
5353
if store_dict is None:
5454
store_dict = {}
5555
self._store_dict = store_dict
@@ -68,7 +68,7 @@ def __eq__(self, other: object) -> bool:
6868
return (
6969
isinstance(other, type(self))
7070
and self._store_dict == other._store_dict
71-
and self.readonly == other.readonly
71+
and self.read_only == other.read_only
7272
)
7373

7474
async def get(
@@ -185,7 +185,7 @@ class GpuMemoryStore(MemoryStore):
185185
store_dict : MutableMapping, optional
186186
A mutable mapping with string keys and :class:`zarr.core.buffer.gpu.Buffer`
187187
values.
188-
readonly : bool, optional
188+
read_only : bool
189189
Whether to open the store in read-only mode.
190190
"""
191191

@@ -195,9 +195,9 @@ def __init__(
195195
self,
196196
store_dict: MutableMapping[str, gpu.Buffer] | None = None,
197197
*,
198-
readonly: bool = False,
198+
read_only: bool = False,
199199
) -> None:
200-
super().__init__(store_dict=store_dict, readonly=readonly) # type: ignore[arg-type]
200+
super().__init__(store_dict=store_dict, read_only=read_only) # type: ignore[arg-type]
201201

202202
def __str__(self) -> str:
203203
return f"gpumemory://{id(self._store_dict)}"

src/zarr/storage/remote.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class RemoteStore(Store):
3030
----------
3131
fs : AsyncFileSystem
3232
The Async FSSpec filesystem to use with this store.
33-
readonly : bool
33+
read_only : bool
3434
Whether the store is read-only
3535
path : str
3636
The root path of the store. This should be a relative path and must not include the
@@ -77,11 +77,11 @@ class RemoteStore(Store):
7777
def __init__(
7878
self,
7979
fs: AsyncFileSystem,
80-
readonly: bool = False,
80+
read_only: bool = False,
8181
path: str = "/",
8282
allowed_exceptions: tuple[type[Exception], ...] = ALLOWED_EXCEPTIONS,
8383
) -> None:
84-
super().__init__(readonly=readonly)
84+
super().__init__(read_only=read_only)
8585
self.fs = fs
8686
self.path = path
8787
self.allowed_exceptions = allowed_exceptions
@@ -102,7 +102,7 @@ def __init__(
102102
def from_upath(
103103
cls,
104104
upath: Any,
105-
readonly: bool = False,
105+
read_only: bool = False,
106106
allowed_exceptions: tuple[type[Exception], ...] = ALLOWED_EXCEPTIONS,
107107
) -> RemoteStore:
108108
"""
@@ -112,7 +112,7 @@ def from_upath(
112112
----------
113113
upath : UPath
114114
The upath to the root of the store.
115-
readonly : bool
115+
read_only : bool
116116
Whether the store is read-only, defaults to False.
117117
allowed_exceptions : tuple, optional
118118
The exceptions that are allowed to be raised when accessing the
@@ -125,7 +125,7 @@ def from_upath(
125125
return cls(
126126
fs=upath.fs,
127127
path=upath.path.rstrip("/"),
128-
readonly=readonly,
128+
read_only=read_only,
129129
allowed_exceptions=allowed_exceptions,
130130
)
131131

@@ -134,7 +134,7 @@ def from_url(
134134
cls,
135135
url: str,
136136
storage_options: dict[str, Any] | None = None,
137-
readonly: bool = False,
137+
read_only: bool = False,
138138
allowed_exceptions: tuple[type[Exception], ...] = ALLOWED_EXCEPTIONS,
139139
) -> RemoteStore:
140140
"""
@@ -146,7 +146,7 @@ def from_url(
146146
The URL to the root of the store.
147147
storage_options : dict, optional
148148
The options to pass to fsspec when creating the filesystem.
149-
readonly : bool
149+
read_only : bool
150150
Whether the store is read-only, defaults to False.
151151
allowed_exceptions : tuple, optional
152152
The exceptions that are allowed to be raised when accessing the
@@ -173,7 +173,7 @@ def from_url(
173173
# `not path.startswith("http")` is a special case for the http filesystem (¯\_(ツ)_/¯)
174174
path = fs._strip_protocol(path)
175175

176-
return cls(fs=fs, path=path, readonly=readonly, allowed_exceptions=allowed_exceptions)
176+
return cls(fs=fs, path=path, read_only=read_only, allowed_exceptions=allowed_exceptions)
177177

178178
async def clear(self) -> None:
179179
# docstring inherited
@@ -191,7 +191,7 @@ def __eq__(self, other: object) -> bool:
191191
return (
192192
isinstance(other, type(self))
193193
and self.path == other.path
194-
and self.readonly == other.readonly
194+
and self.read_only == other.read_only
195195
and self.fs == other.fs
196196
)
197197

src/zarr/storage/zip.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ def __init__(
6565
path: Path | str,
6666
*,
6767
mode: ZipStoreAccessModeLiteral = "r",
68-
readonly: bool | None = None,
68+
read_only: bool | None = None,
6969
compression: int = zipfile.ZIP_STORED,
7070
allowZip64: bool = True,
7171
) -> None:
72-
if readonly is None:
73-
readonly = mode == "r"
72+
if read_only is None:
73+
read_only = mode == "r"
7474

75-
super().__init__(readonly=readonly)
75+
super().__init__(read_only=read_only)
7676

7777
if isinstance(path, str):
7878
path = Path(path)

0 commit comments

Comments
 (0)