Skip to content

Commit a42dc7c

Browse files
committed
Use ANY_ACCESS_MODE
1 parent 23f4376 commit a42dc7c

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/zarr/core/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import (
1111
TYPE_CHECKING,
1212
Any,
13+
Final,
1314
Generic,
1415
Literal,
1516
TypedDict,
@@ -39,6 +40,7 @@
3940
JSON = str | int | float | Mapping[str, "JSON"] | Sequence["JSON"] | None
4041
MemoryOrder = Literal["C", "F"]
4142
AccessModeLiteral = Literal["r", "r+", "a", "w", "w-"]
43+
ANY_ACCESS_MODE: Final = "r", "r+", "a", "w", "w-"
4244
DimensionNames = Iterable[str | None] | None
4345

4446
TName = TypeVar("TName", bound=str)

src/zarr/storage/_common.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44
import json
55
import warnings
66
from pathlib import Path
7-
from typing import TYPE_CHECKING, Any, Literal, Self, TypeAlias, get_args
7+
from typing import TYPE_CHECKING, Any, Literal, Self, TypeAlias
88

99
from zarr.abc.store import ByteRequest, Store
1010
from zarr.core.buffer import Buffer, default_buffer_prototype
11-
from zarr.core.common import ZARR_JSON, ZARRAY_JSON, ZGROUP_JSON, AccessModeLiteral, ZarrFormat
11+
from zarr.core.common import (
12+
ANY_ACCESS_MODE,
13+
ZARR_JSON,
14+
ZARRAY_JSON,
15+
ZGROUP_JSON,
16+
AccessModeLiteral,
17+
ZarrFormat,
18+
)
1219
from zarr.errors import ContainsArrayAndGroupError, ContainsArrayError, ContainsGroupError
1320
from zarr.storage._local import LocalStore
1421
from zarr.storage._memory import MemoryStore
@@ -97,8 +104,8 @@ async def open(cls, store: Store, path: str, mode: AccessModeLiteral | None = No
97104
if mode is None:
98105
return await cls._create_open_instance(store, path)
99106

100-
if mode not in get_args(AccessModeLiteral):
101-
raise ValueError(f"Invalid mode: {mode}, expected one of {AccessModeLiteral}")
107+
if mode not in ANY_ACCESS_MODE:
108+
raise ValueError(f"Invalid mode: {mode}, expected one of {ANY_ACCESS_MODE}")
102109

103110
if store.read_only:
104111
# Don't allow write operations on a read-only store

0 commit comments

Comments
 (0)