feature: Track relationships between narrows of different variables
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 516
- PR merge metrics
- No merged PRs in 30d
Description
Pyrefly should be able to narrow the type of `x` here but doesn't:
```
from typing import reveal_type
def f():
x: int | None = None
b = "foo"
if b == "bar":
x = 3
if b == "bar":
# is it possible to infer that x MUST be 3 here?
reveal_type(x) # revealed type: int | None
```
### Discussed in https://github.com/facebook/pyrefly/discussions/961
Originally posted by **michaelfortunato** August 18, 2025
Is it possible for Pyrefly to see that x must be an int in the second if block as the two predicates are the same and its dependency `b` has not changed?
```python
x: int | None = None
b = "foo"
if b == "bar":
x = 3
if b == "bar":
# is it possible to infer that x MUST be 3 here?
reveal_type(x)
```
https://pyrefly.org/sandbox/?code=MQAg6gpgNgxg9gWwiALnVALZAFAngJwgDMpcQBlAQwDsATAIzgA8AaTASwGcQuRKQADpQDmEAFCgA7lkIhccAK4gYNEJPzsUENpwyVZNWiCgR91PowUpUuAe2rCe5vCgxxqAOgkSQACQgGBsqKAiYgRKYoCoTccEQc3JyGjEwAXD4AtCAA4hDWhJRQGSjsSDYCyDBYMADW9o4REAyUtZkgAKqcyIQAbqZQAPoothAAFACUqOj2nBUw1vYR%2BIRGwxWcbRBMFRpI1NaSmhiYyACSACIAouGR0RDcrpQHyJwKAgJw%2BNajEB7CHnwrHB4AhQnltCBhHBitDaMR7Jp2O42G4%2Bvg2HkYOM2mANFo%2BHQQPgFM5cK53ME4SBaOxCPNSE45Ip8CB6Pg4JIuvgxGIiOyEOV6jxQZ9rAAqMRpJzWAA%2BIAAcu5kABeBVKsT0ECqgBERDgcG1YnY8U1yp19H02vSIBtTC1IAAzEaTVrzZbrTaQKBeJpBHBOJx2PQwmgnEtME8QHaALLtcgAFVZyAdIBkEAA-CAxJ6iRA%2BoUhiNRkxsaBev1CxU1OwoFBBOzaAoYMh%2BGtkAF2SzHtYtLXuPIlK5kG2QHhCCQyHoNqAQQIrE1wp8TrmovhzKN7AllJQujoUPhsUA&version=3.12
Contributor guide
Assessment
This issue has not been assessed yet.