Skip to content

Should we widen the type of the value parameter of Store.set? #2472

Open
@d-v-b

Description

@d-v-b

In main Store.set has the following signature:

async def set(self, key: str, value: Buffer) -> None:

As a developer I want to know why I can't call store.set('foo', bytes_object) -- why do I have to import this Buffer class, then create a buffer from my bytes? I.e., why doesn't store.set take BytesLike?

The Buffer ABC defines 2 class methods for creating buffers from non-buffers: from_bytes and from_array_like. Therefore every Buffer class can turn BytesLike or ArrayLike instances into instances of that class, and so store.set(key, bytes) could just get the default buffer prototype and create the buffer it needs from the byteslike / arraylike provided to set.

So is there any reason why we shouldn't support this new function signature for Store.set?

    async def set(self, key: str, value: BytesLike | ArrayLike | Buffer) -> None:

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew features or improvements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions