Skip to content

Default buffer logic in store ABC #3643

@d-v-b

Description

@d-v-b

the store abc get method requires specifying a buffer prototype. That leads to code like this:

from zarr.core.buffer.core import default_buffer_prototype
from zarr.storage import MemoryStore
from zarr.core.sync import sync
x = MemoryStore()
sync(x.get("foo", prototype=default_buffer_prototype))
# None

But the memorystore implementation of get overrides the base signature to allow prototype to be None which is also the default value, in which case the default buffer prototype is used. This makes the code simpler:

from zarr.storage import MemoryStore
from zarr.core.sync import sync
x = MemoryStore()
sync(x.get("foo"))
# None

I propose that we push this "prototype can be None" logic to the store ABC, and define a method on the ABC like _get_default_buffer_prototype(self, ...) -> BufferPrototype, which can default to the exact logic MemoryStore (and LocalStore) currently uses.

I also note that the prototype parameter is annotated as a BufferPrototype which is effectively a tuple of Buffer and NDBuffer classes, but the stores methods never return NDBuffers, so shouldn't we just take Buffer classes here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions