4
4
import contextlib
5
5
import pickle
6
6
from collections import defaultdict
7
- from typing import TYPE_CHECKING , TypedDict
7
+ from typing import TYPE_CHECKING , Generic , Self , TypedDict , TypeVar
8
8
9
9
from zarr .abc .store import (
10
10
ByteRequest ,
34
34
)
35
35
36
36
37
- class ObjectStore (Store ):
37
+ T_Store = TypeVar ("T_Store" , bound = "_UpstreamObjectStore" )
38
+
39
+
40
+ class ObjectStore (Store , Generic [T_Store ]):
38
41
"""
39
42
Store that uses obstore for fast read/write from AWS, GCP, Azure.
40
43
@@ -51,7 +54,7 @@ class ObjectStore(Store):
51
54
raise an issue with any comments/concerns about the store.
52
55
"""
53
56
54
- store : _UpstreamObjectStore
57
+ store : T_Store
55
58
"""The underlying obstore instance."""
56
59
57
60
def __eq__ (self , value : object ) -> bool :
@@ -61,15 +64,15 @@ def __eq__(self, value: object) -> bool:
61
64
if not self .read_only == value .read_only :
62
65
return False
63
66
64
- return self .store == value .store
67
+ return self .store == value .store # type: ignore[no-any-return]
65
68
66
- def __init__ (self , store : _UpstreamObjectStore , * , read_only : bool = False ) -> None :
69
+ def __init__ (self , store : T_Store , * , read_only : bool = False ) -> None :
67
70
if not store .__class__ .__module__ .startswith ("obstore" ):
68
71
raise TypeError (f"expected ObjectStore class, got { store !r} " )
69
72
super ().__init__ (read_only = read_only )
70
73
self .store = store
71
74
72
- def with_read_only (self , read_only : bool = False ) -> ObjectStore :
75
+ def with_read_only (self , read_only : bool = False ) -> Self :
73
76
# docstring inherited
74
77
return type (self )(
75
78
store = self .store ,
0 commit comments