astral-sh / astral-sh/ruff

Feature request: Local variable never read

Open
#13,541 2 comments 3 reactions 0 assignees View on GitHub
needs-decision rule
Dominant language
Rust
Stars
49.6k
Forks
2.4k
Avg merge
1d 21h
Merged PRs (30d)
435

Description

It'd be useful to track if a local variable was read before assigned again:
```python
def main():
x = 5
x = 6
print(x)
```
A common use-case is simply typos or using `if` instead of `elif`:
```python
if case1:
x = 1
if case2:
x = 2
else:
x = 3
```
Where `x = 1` is never used.
The correct snippet after fixing the mistake would be:
```python
if case1:
x = 1
elif case2:
x = 2
else:
x = 3
```

Contributor guide

Open the contributing guide

Research direction

Start by comparing the two Python examples and define when an assignment is considered unused before the variable is reassigned. Done means the requested cases are detected without flagging the final value that is later read, with coverage for both the sequential assignments and the if/elif control flow.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.