Skip to content

Mypy not treating bytes as typing.ByteString #7714

@willmcgugan

Description

@willmcgugan

According to the docs, an argument typed as bytes should also accept bytearray and memoryview, but this doesn't seem to be the case.

The following example demonstrates this:

def process(b: bytes) -> None:
    pass

process(memoryview(b"foo"))

Mypy produces the following error:

error: Argument 1 to "process" has incompatible type "memoryview"; expected "bytes"

I found #4871 which is essentially the same issue. If there hasn't been any relevant changes since April 2008, perhaps its a docs issue only?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions