KotlinIsland / KotlinIsland/basedmypy

union with intersection doesn't narrow properly

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.