KotlinIsland / KotlinIsland/basedmypy
`redundant-expr`/`unreachable` false positive when narrowing type with generic to subtype
- Dominant language
- Python
- Stars
- 202
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
```python
from typing import TypeVar, Generic, _T as T
class A(Generic[T]): ...
class B(A[int]): ...
a: A[object]
assert isinstance(a, B) # error: Intersection of "A[object] & B" cannot exist: would have inconsistent method resolution order [unreachable]
print("hi") # error: Statement is unreachable [unreachable]
```
[playground](https://mypy-play.net/?mypy=basedmypy-latest&python=3.12&gist=36f3c4f2cdb3a0e91b0c831ec4a236e8)
Contributor guide
Research direction
Reproduce the example in the linked mypy playground using Python 3.12 and the basedmypy-latest configuration. Trace how isinstance narrowing handles the generic A[object] and subtype B, then verify that the assertion is not reported as unreachable and the following print statement remains reachable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100