facebook / facebook/pyrefly

Pyrefly does not eliminate conditional expression branches based on previous narrowing

Open
#3,349 4 comments 0 reactions 0 assignees View on GitHub
narrowing scoping-control-flow
Dominant language
Rust
Stars
7k
Forks
516
PR merge metrics
No merged PRs in 30d

Description

### Describe the Bug

```python
def f(x: int | None) -> None:
if x is not None:
y = 1 if x is not None else None # since we guard that x is not None, we could prune away the `else None` case in the ternary
assert_type(y, int)
```

Python: 3.12

### Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSImMYABGABT6I0ToAuNAPjQHK7owAlDQC0APl78YiADroaClrXws4NdLg58Bs%2BYv2kaAXhoBGJTRUQ1GrVJowocGJIFz9%2B1HGcAnNgH02UmIYelIAGhZ2QRBwkDIfaihSQjZcAFsoCgBiGgAFUkSwZJo0LDwVAGN%2BSABzAFcfVDYIfkI5XIBlGBcACzY2YjhEAHoRhKSU3B9akZh0EcxcSrgR6vQ6xubWhbppmlQAN1RoVGxYGnXNppb%2BGlxiW-Q4dvQyNl7%2BEUOYHzgd4w0GQgADMhFMACZgXIANq-HzTOAAXTk9XQEHSxGmbBgmBEmAgiUqLR%2BgIA5BBahpEmS5LYRIkAI71Qm4kQAaxgpBEqEqlXgahMZIA7qgfOhaegQABfOK8kkwABi0BgFDKOAIJHI0qAA

### (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.