Skip to content

False positive: Condition will always evaluate to False since the types "bytearray" and "bytes" have no overlap #11433

@max-kamps

Description

@max-kamps

Playground link

data1 = bytearray(4)
data2 = bytes(4)

if data1 == data2:
    print("Four zeros are four zeros!")

Results in the warning Condition will always evaluate to False since the types "bytearray" and "bytes" have no overlap.

But this is incorrect, comparing bytearray and bytes with == returns True if they have the same content.

A related issue occurs with literals:

data = bytearray(4)
value = b"\0\0\0\0"

if data == value:
    print("Four zeros are four zeros!")

Results in the warning Condition will always evaluate to False since the types "bytearray" and "Literal[b"\x00\x00\x00\x00"]" have no overlap.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions