KotlinIsland / KotlinIsland/basedmypy

return type on `isinstance` check with non-overlapping types is `bool` instead of `False`

Open
#616 0 comments 0 reactions 0 assignees View on GitHub
bug
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.