pyright icon indicating copy to clipboard operation
pyright copied to clipboard

False positive "Condition will always evaluate to False"

Open rcls opened this issue 3 months ago • 0 comments

Describe the bug

A == comparison between a bytearray instance and a bytes instance, when checked with pyright at strict level, gets an error: "Condition will always evaluate to False since the types "bytearray" and "bytes" have no overlap".

This is incorrect, python overloads == for this case.

(It might actually be considered useful to be able to report this as a type error. But even in that case, the current pyright error message is not correct.)

Code or Screenshots

Example. The assert passes, even though pyright claims "always ... False'.

def foo(x: bytes, y: bytes) -> bool:
    return bytearray(x) == y

assert foo(b'1234', b'1234')

See https://pyright-play.net/?pyrightVersion=1.1.407&pythonVersion=3.14&strict=true&code=CYUwZgBGD20BQA8BcEBGBPALiAzgGgnRQ2xwEoIBaAPjVgBskAoCViAJxEwFd2A7NFhABDdu2HpEFALzTCTJsJw4Q7TFFhxUAcgCMAJgDMAFm0EdBk9rJMgA

rcls avatar Nov 03 '25 00:11 rcls