False positive: Condition will always evaluate to False since the types "bytearray" and "bytes" have no overlap
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
[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`.
Contributor guide
Research direction
Start with the linked Pyright Playground examples and trace how equality between bytearray and bytes is analyzed, including the bytes literal case. Add or update regression coverage for both examples, and consider the issue done when valid equal-content comparisons no longer produce the no-overlap warning without weakening genuinely incompatible comparisons.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100