Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
d-v-b opened this issue Nov 8, 2024 · 0 comments
Open

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

d-v-b opened this issue Nov 8, 2024 · 0 comments

Comments

@d-v-b
Copy link
Contributor

d-v-b commented Nov 8, 2024

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:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant