facebook / facebook/pyrefly

`del` in dead code should make variable local

Open
#2,930 1 comment 0 reactions 0 assignees View on GitHub
typechecking
Dominant language
Rust
Stars
7k
Forks
516
PR merge metrics
No merged PRs in 30d

Description

Even though `del` is in unreachable code (`if False`), Python's compiler still marks the variable as local in the enclosing scope. Pyrefly should recognize this and report that `x` may be unbound.

```python
x = 1

def f():
print(x)
if False:
del x
```

**Sandbox:** [Pyrefly](https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXAAlHAhgOwCYCMD2AHgHQAOAnksiIcgLzICMAOpq9jGMmABQCUiVsmHJSAJwiYALj0J8hIiFwBi6KHBiDMIncg5RkhViAC%2BAGmroAxlIgA3GMugwqIDDgIkKpoA)

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.