44import contextlib
55import pickle
66from collections import defaultdict
7- from typing import TYPE_CHECKING , TypedDict
7+ from typing import TYPE_CHECKING , Generic , Self , TypedDict , TypeVar
88
99from zarr .abc .store import (
1010 ByteRequest ,
3434)
3535
3636
37- class ObjectStore (Store ):
37+ T_Store = TypeVar ("T_Store" , bound = "_UpstreamObjectStore" )
38+
39+
40+ class ObjectStore (Store , Generic [T_Store ]):
3841 """
3942 Store that uses obstore for fast read/write from AWS, GCP, Azure.
4043
@@ -51,7 +54,7 @@ class ObjectStore(Store):
5154 raise an issue with any comments/concerns about the store.
5255 """
5356
54- store : _UpstreamObjectStore
57+ store : T_Store
5558 """The underlying obstore instance."""
5659
5760 def __eq__ (self , value : object ) -> bool :
@@ -61,15 +64,15 @@ def __eq__(self, value: object) -> bool:
6164 if not self .read_only == value .read_only :
6265 return False
6366
64- return self .store == value .store
67+ return self .store == value .store # type: ignore[no-any-return]
6568
66- def __init__ (self , store : _UpstreamObjectStore , * , read_only : bool = False ) -> None :
69+ def __init__ (self , store : T_Store , * , read_only : bool = False ) -> None :
6770 if not store .__class__ .__module__ .startswith ("obstore" ):
6871 raise TypeError (f"expected ObjectStore class, got { store !r} " )
6972 super ().__init__ (read_only = read_only )
7073 self .store = store
7174
72- def with_read_only (self , read_only : bool = False ) -> ObjectStore :
75+ def with_read_only (self , read_only : bool = False ) -> Self :
7376 # docstring inherited
7477 return type (self )(
7578 store = self .store ,
0 commit comments