ITADN

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

#11433Openmax-kamps 创建于 2026-05-11
bug
M
max-kampscommented
[Playground link](https://pyright-play.net/?strict=true&code=CYQwLiCMAEC80CMCeYCmIBOGRIBQBYBKAKFAgCY5EVUBnAk4gSwDNoyo54PyAuY6IOgAHDEwB2YXACIAYgHsArhmgAvVBnm1omVNBZKV6zbQCE0xhyrI0mbHiLEAbiAA2ivfATSAOgAZ-QL9pYmY2K1h4F3dUfiERMUkZBWU1DS0dDD0DVOMtc0IgA) ```python 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: ```python 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`.
0 条评论