88from typing import TYPE_CHECKING , Literal , Protocol , runtime_checkable
99
1010from zarr .core .buffer import Buffer , BufferPrototype
11- from zarr .core .buffer .core import default_buffer_prototype
1211from zarr .core .sync import sync
12+ from zarr .registry import get_buffer_class
1313
1414if TYPE_CHECKING :
1515 from collections .abc import AsyncGenerator , AsyncIterator , Iterable
1616 from types import TracebackType
1717 from typing import Any , Self , TypeAlias
1818
19- __all__ = ["BufferLike " , "ByteGetter" , "ByteSetter" , "Store" , "set_or_delete" ]
19+ __all__ = ["BufferClassLike " , "ByteGetter" , "ByteSetter" , "Store" , "set_or_delete" ]
2020
21- BufferLike = type [Buffer ] | BufferPrototype
21+ BufferClassLike = type [Buffer ] | BufferPrototype
22+ """An object that is or contains a Buffer class"""
2223
2324
2425@dataclass
@@ -189,13 +190,13 @@ def _get_default_buffer_class(self) -> type[Buffer]:
189190 """
190191 Get the default buffer class.
191192 """
192- return default_buffer_prototype (). buffer
193+ return get_buffer_class ()
193194
194195 @abstractmethod
195196 async def get (
196197 self ,
197198 key : str ,
198- prototype : BufferLike | None = None ,
199+ prototype : BufferClassLike | None = None ,
199200 byte_range : ByteRequest | None = None ,
200201 ) -> Buffer | None :
201202 """Retrieve the value associated with a given key.
@@ -225,7 +226,7 @@ async def _get_bytes(
225226 self ,
226227 key : str ,
227228 * ,
228- prototype : BufferLike | None = None ,
229+ prototype : BufferClassLike | None = None ,
229230 byte_range : ByteRequest | None = None ,
230231 ) -> bytes :
231232 """
@@ -268,7 +269,7 @@ async def _get_bytes(
268269 --------
269270 >>> store = await MemoryStore.open()
270271 >>> await store.set("data", Buffer.from_bytes(b"hello world"))
271- >>> data = await store._get_bytes("data", prototype=default_buffer_prototype() )
272+ >>> data = await store._get_bytes("data")
272273 >>> print(data)
273274 b'hello world'
274275 """
@@ -281,7 +282,7 @@ def _get_bytes_sync(
281282 self ,
282283 key : str = "" ,
283284 * ,
284- prototype : BufferLike | None = None ,
285+ prototype : BufferClassLike | None = None ,
285286 byte_range : ByteRequest | None = None ,
286287 ) -> bytes :
287288 """
@@ -329,7 +330,7 @@ def _get_bytes_sync(
329330 --------
330331 >>> store = MemoryStore()
331332 >>> await store.set("data", Buffer.from_bytes(b"hello world"))
332- >>> data = store._get_bytes_sync("data", prototype=default_buffer_prototype() )
333+ >>> data = store._get_bytes_sync("data")
333334 >>> print(data)
334335 b'hello world'
335336 """
@@ -340,7 +341,7 @@ async def _get_json(
340341 self ,
341342 key : str ,
342343 * ,
343- prototype : BufferLike | None = None ,
344+ prototype : BufferClassLike | None = None ,
344345 byte_range : ByteRequest | None = None ,
345346 ) -> Any :
346347 """
@@ -387,7 +388,7 @@ async def _get_json(
387388 >>> store = await MemoryStore.open()
388389 >>> metadata = {"zarr_format": 3, "node_type": "array"}
389390 >>> await store.set("zarr.json", Buffer.from_bytes(json.dumps(metadata).encode()))
390- >>> data = await store._get_json("zarr.json", prototype=default_buffer_prototype() )
391+ >>> data = await store._get_json("zarr.json")
391392 >>> print(data)
392393 {'zarr_format': 3, 'node_type': 'array'}
393394 """
@@ -398,7 +399,7 @@ def _get_json_sync(
398399 self ,
399400 key : str = "" ,
400401 * ,
401- prototype : BufferLike | None = None ,
402+ prototype : BufferClassLike | None = None ,
402403 byte_range : ByteRequest | None = None ,
403404 ) -> Any :
404405 """
@@ -451,7 +452,7 @@ def _get_json_sync(
451452 >>> store = MemoryStore()
452453 >>> metadata = {"zarr_format": 3, "node_type": "array"}
453454 >>> store.set("zarr.json", Buffer.from_bytes(json.dumps(metadata).encode()))
454- >>> data = store._get_json_sync("zarr.json", prototype=default_buffer_prototype() )
455+ >>> data = store._get_json_sync("zarr.json")
455456 >>> print(data)
456457 {'zarr_format': 3, 'node_type': 'array'}
457458 """
@@ -461,7 +462,7 @@ def _get_json_sync(
461462 @abstractmethod
462463 async def get_partial_values (
463464 self ,
464- prototype : BufferLike | None ,
465+ prototype : BufferClassLike | None ,
465466 key_ranges : Iterable [tuple [str , ByteRequest | None ]],
466467 ) -> list [Buffer | None ]:
467468 """Retrieve possibly partial values from given key_ranges.
@@ -645,7 +646,7 @@ def close(self) -> None:
645646 self ._is_open = False
646647
647648 async def _get_many (
648- self , requests : Iterable [tuple [str , BufferLike | None , ByteRequest | None ]]
649+ self , requests : Iterable [tuple [str , BufferClassLike | None , ByteRequest | None ]]
649650 ) -> AsyncGenerator [tuple [str , Buffer | None ], None ]:
650651 """
651652 Retrieve a collection of objects from storage. In general this method does not guarantee
@@ -676,10 +677,8 @@ async def getsize(self, key: str) -> int:
676677 # Note to implementers: this default implementation is very inefficient since
677678 # it requires reading the entire object. Many systems will have ways to get the
678679 # size of an object without reading it.
679- # avoid circular import
680- from zarr .core .buffer .core import default_buffer_prototype
681680
682- value = await self .get (key , prototype = default_buffer_prototype () )
681+ value = await self .get (key )
683682 if value is None :
684683 raise FileNotFoundError (key )
685684 return len (value )
0 commit comments