Skip to content

memoryview support in BytesIO #3423

@zaq32

Description

@zaq32

mypy complains about following piece of code:

from io import BytesIO

view = memoryview(b'ABCD')
bio = BytesIO(view)

target = BytesIO()
target.write(view)

The errors are:

test.py:4: error: Argument 1 to "BytesIO" has incompatible type "memoryview"; expected "bytes"
test.py:7: error: Argument 1 to "write" of "BytesIO" has incompatible type "memoryview"; expected "Union[bytes, bytearray]"

According to documentation BytesIO should be constructible from bytes-like object:
https://docs.python.org/3/library/io.html#io.BytesIO
which is among others memoryview: https://docs.python.org/3/glossary.html#term-bytes-like-object

Similarly argument to write should be bytes-like object:
https://docs.python.org/3/library/io.html#io.BufferedIOBase

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions