KotlinIsland / KotlinIsland/basedmypy
union with intersection doesn't narrow properly
- Dominant language
- Python
- Stars
- 202
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
upstream issue, but:
```py
class A: ...
class B: ...
class C: ...
other: (A & B) | C
data: B | C
data = other
if isinstance(data, A):
reveal_type(data) # Never
```
should be `(A & B) | (A & C)`
interestingly, this only occurs when it's narrowed and doesn't happen when you specify the type explicitly `data: (A & B) | C`
Contributor guide
Research direction
Start with the Python reproduction in the issue and trace the type-narrowing path that handles `isinstance(data, A)` for the union involving an intersection. Done means the revealed type is `(A & B) | (A & C)` rather than `Never`, while the explicitly annotated case continues to behave correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100