KotlinIsland / KotlinIsland/basedmypy
return type on `isinstance` check with non-overlapping types is `bool` instead of `False`
- Dominant language
- Python
- Stars
- 202
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the problem, ie expected/actual result (if it's not blatantly obvious)
this prevents you from being able to use `cast` to work around `redundant-expr` false positives (eg. #615)
### Gist to reproduce
```python
# mypy: enable-error-code=redundant-expr
from typing import cast
b = 1
reveal_type(isinstance(b, str)) # bool, should be False
if isinstance(b, str): # error: condition is always false
...
if cast(bool, isinstance(b, str)): # error: redundant expr
...
```
Contributor guide
Research direction
Begin with the supplied Python reproduction and compare the revealed type with the redundant-expr diagnostic. Locate the existing isinstance type-checking tests or implementation, then add regression coverage showing that non-overlapping types reveal False without breaking the existing diagnostic behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100