facebook / facebook/pyrefly

disjointedness not considered when narrowing a union

Open
#1,140 2 comments 0 reactions 0 assignees View on GitHub
narrowing needs-discussion typechecking
Dominant language
Rust
Stars
7k
Forks
519
PR merge metrics
No merged PRs in 30d

Description

### Describe the Bug

```py
class A: ...

def f(a: A | list[int]):
if isinstance(a, list):
# here pyrefly narrows `a` to `list[int]`, which is incorrect because `A` and `list[int]` are not disjoint
a.pop() + 1

class B(A, list[str]): ...

f(B(["i'm not an int"]))
```

### Sandbox Link

_No response_

### (Only applicable for extension issues) IDE Information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.