Skip to content

bytes | str incorrectly interpreted as bytes | bytearray | memoryview[_I@memoryview] | str #8834

@pavel-wmt

Description

@pavel-wmt

Describe the bug
bytes | str incorrectly interpreted as bytes | bytearray | memoryview[_I@memoryview] | str

Code or Screenshots
This should type check

def fn(arg: bytes | str) -> str:
    if isinstance(arg, bytes):
        return arg.decode()
    return arg

But it produces error:

/home/pavelaslanov/bytes-or-str-error.py
  /home/pavelaslanov/bytes-or-str-error.py:4:12 - error: Expression of type "bytearray | memoryview[_I@memoryview] | str" is incompatible with return type "str"
    Type "bytearray | memoryview[_I@memoryview] | str" is incompatible with type "str"
      "bytearray" is incompatible with "str" (reportReturnType)
1 error, 0 warnings, 0 informations 

VS Code extension or command-line
pyright 1.1.377

Metadata

Metadata

Assignees

No one assigned

    Labels

    as designedNot a bug, working as intendedbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions