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

BytesLike type should accept collections.abc.Buffer #2814

Open
kylebarron opened this issue Feb 10, 2025 · 0 comments
Open

BytesLike type should accept collections.abc.Buffer #2814

kylebarron opened this issue Feb 10, 2025 · 0 comments

Comments

@kylebarron
Copy link

In #1661 (comment), there are currently some failing mypy lints of the type

src/zarr/storage/_object.py:160: error: Argument 1 to "from_bytes" of "Buffer" has incompatible type "Bytes"; expected "bytes | bytearray | memoryview[int]"  [arg-type]

The Bytes type in obstore is a CPU byte buffer that is backed by Rust and implements the Python buffer protocol. The type hint for Bytes subclasses from collections.abc.Buffer. BytesLike is defined here:

BytesLike = bytes | bytearray | memoryview

and should be updated to be

BytesLike = bytes | bytearray | memoryview

or, just

BytesLike = Buffer

because all 3 of those types implement Buffer.

This change requires some other typing changes, because the numpy type hints (e.g. for from_buffer) do not correctly allow collections.abc.Buffer as an input type.

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