astral-sh / astral-sh/ruff

F841 does not have branch analysis

Open
#16,752 1 comment 0 reactions 0 assignees View on GitHub
rule type-inference
Dominant language
Rust
Stars
49.7k
Forks
2.4k
Avg merge
2d 1h
Merged PRs (30d)
458

Description

### Summary

F841 does not report variables that are unused in certain branches. Below is a short example ([playground](https://play.ruff.rs/0e1d38e6-17b0-4355-a37a-089d454de311)) showing the issue

```python
def func(x):
if x:
io = ""
else:
io = "foo"
print(io)
```

This issue was [originally reported](https://github.com/PyCQA/pyflakes/issues/758) to pyflakes and closed as duplicate of https://github.com/PyCQA/pyflakes/issues/715.

They mention is unlikely they will implement branch analysis, but ruff already has (I guess) the machinery needed to support this use case.

### Version

v0.11.0 (playground)

Contributor guide

Open the contributing guide

Research direction

Start with the linked playground example and inspect Ruff's F841 rule and the existing branch-analysis machinery. Reproduce the example, then determine the expected diagnostic for the branch-local unused variable; done means F841 reports the appropriate unused variable without regressing existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.