Skip to content

BytesLike type should accept collections.abc.Buffer #2814

@kylebarron

Description

@kylebarron

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions