facebook / facebook/pyrefly

Could `unbound-name` be made less noisy?

Open
#3,185 3 comments 0 reactions 0 assignees View on GitHub
narrowing needs-discussion quansight typechecking
Dominant language
Rust
Stars
7k
Forks
516
PR merge metrics
No merged PRs in 30d

Description

### Describe the Bug

```py
def main(a: bool) -> int:
if a:
b = 3

c = 5

if a:
return b
return 9
```

I get
```
ERROR sandbox.py:8:16-17: `b` may be uninitialized [[unbound-name](https://pyrefly.org/en/docs/error-kinds/#unbound-name)]
```

If `b` is defined within an `if a` block, and then only ever used in subsequent `if a` blocks, and `a` is never modified, then could the `unbound-name` not be reported?

---

side-note: I got an internal error the first time I tried putting into into the pyrefly sandbox 🤷

### Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSImMYABALaoToAUqiNeuUAlDQLQA%2BGkwAuiADroa04bTaSZijjQC8NAMwKZW6QGNVNAKySdsmvKlLpAJxgiArtanZTth05oBOEABoQZWzAoUkIRXDooCgBiGgAFUkDgmjQsPHwaXVx0SABzR1QRCCzCSRiAZRgYGgALERFiOEQAeiaA6mDCXGscpph0JsxcXTgmzOyIPOsCov6aMC7zADdGKFRsWAys3PzCrJpcYl30OBL0MhFqrL5FmGs4GYNxEHVCAEYAJifJAG1b6y64ABdST2dAQOjELoiGCYPiYCC2XSFG4GADkE3QXRgqMkmJEfFsAEd7AiYXwANYwUh8VC6XTwOBogDuqCcOPQIAAvn5aciYAAxaAwCgpHAEEjkTlAA

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