KotlinIsland / KotlinIsland/basedmypy

`redundant-expr`/`unreachable` false positive when narrowing type with generic to subtype

Open
#694 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

```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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.