Support reportUnnecessaryComparison for class instances
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
**Describe the bug**
NOTE: This is feature request not bug report.
If I compare class instance(e.g., UUID) to others in strict mode, I get no error. I know this is not a bug since `__eq__` can receive `object`. But I think `reportUnnecessaryComparison` can be applied to class instances, as it works for scalar types such as `int`, `str` and so on.
**Code or Screenshots**
```python
import uuid
a: uuid.UUID = uuid.uuid4()
b: int = 1
# this is not error
# but it would be helpful if pyright can detect this and raise reportUnnecessaryComparison error.
_ = a == b
```
playground: https://pyright-play.net/?pyrightVersion=1.1.410&pythonVersion=3.13&strict=true&code=JYWwDg9gTgLgBAVwcAJgWAFCYIYC5HIoB0AqiQJIAicAvAakUqgCwAUAlJgEb7AB28OgEZMAfVpxstOlyA
Contributor guide
Research direction
Start with the linked pyright-play example and its strict-mode configuration to reproduce the missing diagnostic. Locate the implementation and tests for reportUnnecessaryComparison, then add coverage for comparing a UUID instance with an int; done means the requested diagnostic is reported without breaking valid class-instance comparisons.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100