Skip to content

Commit bf58808

Browse files
committed
Don't implement _is_open setter on wrapped stores
1 parent 5148dd6 commit bf58808

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

src/zarr/storage/_logging.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ def _is_open(self) -> bool:
137137

138138
@_is_open.setter
139139
def _is_open(self, value: bool) -> None:
140-
with self.log(value):
141-
self._store._is_open = value
140+
raise NotImplementedError("LoggingStore must be opened via the `_open` method")
142141

143142
async def _open(self) -> None:
144143
with self.log():

src/zarr/storage/_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def _is_open(self) -> bool:
6262

6363
@_is_open.setter
6464
def _is_open(self, value: bool) -> None:
65-
self._store._is_open = value
65+
raise NotImplementedError("WrapperStore must be opened via the `_open` method")
6666

6767
async def clear(self) -> None:
6868
return await self._store.clear()

tests/test_store/test_logging.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ async def test_default_handler(self, local_store, capsys) -> None:
7171
for h in handlers:
7272
logging.getLogger().addHandler(h)
7373

74+
def test_is_open_setter_raises(self, store: LoggingStore) -> None:
75+
"Test that a user cannot change `_is_open` without opening the underlying store."
76+
with pytest.raises(
77+
NotImplementedError, match="LoggingStore must be opened via the `_open` method"
78+
):
79+
store._is_open = True
80+
7481

7582
@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"])
7683
async def test_logging_store(store: Store, caplog) -> None:

tests/test_store/test_wrapper.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ def test_store_supports_listing(self, store: WrapperStore) -> None:
5252
def test_store_repr(self, store: WrapperStore) -> None:
5353
assert str(store) == f"wrapping-file://{store._store.root.as_posix()}"
5454

55+
def test_is_open_setter_raises(self, store: WrapperStore) -> None:
56+
"Test that a user cannot change `_is_open` without opening the underlying store."
57+
with pytest.raises(
58+
NotImplementedError, match="WrapperStore must be opened via the `_open` method"
59+
):
60+
store._is_open = True
61+
5562

5663
@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=True)
5764
async def test_wrapped_set(store: Store, capsys: pytest.CaptureFixture[str]) -> None:

0 commit comments

Comments
 (0)