Skip to content

Commit 6cafeb9

Browse files
committed
Fix typing errors in test_object
1 parent 5529a46 commit 6cafeb9

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ module = [
366366
"tests.test_store.test_memory",
367367
"tests.test_store.test_core",
368368
"tests.test_store.test_logging",
369+
"tests.test_store.test_object",
369370
]
370371
strict = false
371372

@@ -375,7 +376,6 @@ strict = false
375376
module = [
376377
"tests.test_codecs.test_codecs",
377378
"tests.test_metadata.*",
378-
"tests.test_store.test_object",
379379
"tests.test_store.test_stateful",
380380
"tests.test_store.test_wrapper",
381381
"tests.test_group",

src/zarr/storage/_obstore.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import pickle
66
from collections import defaultdict
77
from collections.abc import Iterable
8-
from typing import TYPE_CHECKING, Any, TypedDict
8+
from typing import TYPE_CHECKING, Any, Generic, TypedDict, TypeVar
9+
10+
from obstore.store import ObjectStore as _UpstreamObjectStore
911

1012
from zarr.abc.store import (
1113
ByteRequest,
@@ -22,11 +24,11 @@
2224
from typing import Any
2325

2426
from obstore import ListResult, ListStream, ObjectMeta, OffsetRange, SuffixRange
25-
from obstore.store import ObjectStore as _UpstreamObjectStore
2627

2728
from zarr.core.buffer import Buffer, BufferPrototype
2829
from zarr.core.common import BytesLike
2930

31+
3032
__all__ = ["ObjectStore"]
3133

3234
_ALLOWED_EXCEPTIONS: tuple[type[Exception], ...] = (
@@ -35,8 +37,10 @@
3537
NotADirectoryError,
3638
)
3739

40+
T_Store = TypeVar("T_Store", bound=_UpstreamObjectStore)
3841

39-
class ObjectStore(Store):
42+
43+
class ObjectStore(Store, Generic[T_Store]):
4044
"""
4145
Store that uses obstore for fast read/write from AWS, GCP, Azure.
4246
@@ -53,19 +57,17 @@ class ObjectStore(Store):
5357
raise an issue with any comments/concerns about the store.
5458
"""
5559

56-
store: _UpstreamObjectStore
60+
store: T_Store
5761
"""The underlying obstore instance."""
5862

5963
def __eq__(self, value: object) -> bool:
60-
if not isinstance(value, ObjectStore):
61-
return False
62-
63-
if not self.read_only == value.read_only:
64-
return False
65-
66-
return self.store == value.store
64+
return bool(
65+
isinstance(value, ObjectStore)
66+
and self.read_only == value.read_only
67+
and self.store == value.store
68+
)
6769

68-
def __init__(self, store: _UpstreamObjectStore, *, read_only: bool = False) -> None:
70+
def __init__(self, store: T_Store, *, read_only: bool = False) -> None:
6971
if not store.__class__.__module__.startswith("obstore"):
7072
raise TypeError(f"expected ObjectStore class, got {store!r}")
7173
super().__init__(read_only=read_only)

tests/test_store/test_object.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import pytest
55

66
obstore = pytest.importorskip("obstore")
7+
from pathlib import Path
8+
79
import pytest
810
from hypothesis.stateful import (
911
run_state_machine_as_test,
@@ -16,47 +18,43 @@
1618
from zarr.testing.store import StoreTests
1719

1820

19-
class TestObjectStore(StoreTests[ObjectStore, cpu.Buffer]):
21+
class TestObjectStore(StoreTests[ObjectStore[LocalStore], cpu.Buffer]):
2022
store_cls = ObjectStore
2123
buffer_cls = cpu.Buffer
2224

2325
@pytest.fixture
24-
def store_kwargs(self, tmpdir) -> dict[str, Any]:
25-
store = LocalStore(prefix=tmpdir)
26+
def store_kwargs(self, tmp_path: Path) -> dict[str, Any]:
27+
store = LocalStore(prefix=str(tmp_path))
2628
return {"store": store, "read_only": False}
2729

2830
@pytest.fixture
29-
def store(self, store_kwargs: dict[str, str | bool]) -> ObjectStore:
31+
async def store(self, store_kwargs: dict[str, Any]) -> ObjectStore[LocalStore]:
3032
return self.store_cls(**store_kwargs)
3133

32-
async def get(self, store: ObjectStore, key: str) -> Buffer:
33-
assert isinstance(store.store, LocalStore)
34+
async def get(self, store: ObjectStore[LocalStore], key: str) -> Buffer:
3435
new_local_store = LocalStore(prefix=store.store.prefix)
3536
return self.buffer_cls.from_bytes(obstore.get(new_local_store, key).bytes())
3637

37-
async def set(self, store: ObjectStore, key: str, value: Buffer) -> None:
38-
assert isinstance(store.store, LocalStore)
38+
async def set(self, store: ObjectStore[LocalStore], key: str, value: Buffer) -> None:
3939
new_local_store = LocalStore(prefix=store.store.prefix)
4040
obstore.put(new_local_store, key, value.to_bytes())
4141

42-
def test_store_repr(self, store: ObjectStore) -> None:
42+
def test_store_repr(self, store: ObjectStore[LocalStore]) -> None:
4343
from fnmatch import fnmatch
4444

4545
pattern = "ObjectStore(object_store://LocalStore(*))"
4646
assert fnmatch(f"{store!r}", pattern)
4747

48-
def test_store_supports_writes(self, store: ObjectStore) -> None:
48+
def test_store_supports_writes(self, store: ObjectStore[LocalStore]) -> None:
4949
assert store.supports_writes
5050

51-
async def test_store_supports_partial_writes(self, store: ObjectStore) -> None:
51+
def test_store_supports_partial_writes(self, store: ObjectStore[LocalStore]) -> None:
5252
assert not store.supports_partial_writes
53-
with pytest.raises(NotImplementedError):
54-
await store.set_partial_values([("foo", 0, b"\x01\x02\x03\x04")])
5553

56-
def test_store_supports_listing(self, store: ObjectStore) -> None:
54+
def test_store_supports_listing(self, store: ObjectStore[LocalStore]) -> None:
5755
assert store.supports_listing
5856

59-
def test_store_equal(self, store: ObjectStore) -> None:
57+
def test_store_equal(self, store: ObjectStore[LocalStore]) -> None:
6058
"""Test store equality"""
6159
# Test equality against a different instance type
6260
assert store != 0
@@ -73,14 +71,14 @@ def test_store_equal(self, store: ObjectStore) -> None:
7371
def test_store_init_raises(self) -> None:
7472
"""Test __init__ raises appropriate error for improper store type"""
7573
with pytest.raises(TypeError):
76-
ObjectStore("path/to/store")
74+
ObjectStore("path/to/store") # type: ignore[type-var]
7775

7876

7977
@pytest.mark.slow_hypothesis
80-
def test_zarr_hierarchy():
78+
def test_zarr_hierarchy() -> None:
8179
sync_store = ObjectStore(MemoryStore())
8280

8381
def mk_test_instance_sync() -> ZarrHierarchyStateMachine:
8482
return ZarrHierarchyStateMachine(sync_store)
8583

86-
run_state_machine_as_test(mk_test_instance_sync)
84+
run_state_machine_as_test(mk_test_instance_sync) # type ignore[no-untyped-call]

0 commit comments

Comments
 (0)