-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
F841
false negative on assignment to multiple variables (#8489)
## Summary Closes #8441 behind preview feature flag. ## Test Plan `cargo test`
- Loading branch information
Showing
7 changed files
with
136 additions
and
12 deletions.
There are no files selected for viewing
8 changes: 4 additions & 4 deletions
8
crates/ruff_linter/resources/test/fixtures/pyflakes/F841_1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
crates/ruff_linter/resources/test/fixtures/pyflakes/F841_4.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""Test fix for issue #8441. | ||
Ref: https://github.com/astral-sh/ruff/issues/8441 | ||
""" | ||
|
||
|
||
def foo(): | ||
... | ||
|
||
|
||
def bar(): | ||
a = foo() | ||
b, c = foo() | ||
|
||
|
||
def baz(): | ||
d, _e = foo() | ||
print(d) | ||
|
||
|
||
def qux(): | ||
f, _ = foo() | ||
print(f) | ||
|
||
|
||
def quux(): | ||
g, h = foo() | ||
print(g, h) | ||
|
||
|
||
def quuz(): | ||
_i, _j = foo() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...ter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F841_F841_4.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
--- | ||
F841_4.py:12:5: F841 [*] Local variable `a` is assigned to but never used | ||
| | ||
11 | def bar(): | ||
12 | a = foo() | ||
| ^ F841 | ||
13 | b, c = foo() | ||
| | ||
= help: Remove assignment to unused variable `a` | ||
|
||
ℹ Suggested fix | ||
9 9 | | ||
10 10 | | ||
11 11 | def bar(): | ||
12 |- a = foo() | ||
12 |+ foo() | ||
13 13 | b, c = foo() | ||
14 14 | | ||
15 15 | | ||
|
||
|
41 changes: 41 additions & 0 deletions
41
...ules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F841_F841_4.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
--- | ||
F841_4.py:12:5: F841 [*] Local variable `a` is assigned to but never used | ||
| | ||
11 | def bar(): | ||
12 | a = foo() | ||
| ^ F841 | ||
13 | b, c = foo() | ||
| | ||
= help: Remove assignment to unused variable `a` | ||
|
||
ℹ Suggested fix | ||
9 9 | | ||
10 10 | | ||
11 11 | def bar(): | ||
12 |- a = foo() | ||
12 |+ foo() | ||
13 13 | b, c = foo() | ||
14 14 | | ||
15 15 | | ||
|
||
F841_4.py:13:5: F841 Local variable `b` is assigned to but never used | ||
| | ||
11 | def bar(): | ||
12 | a = foo() | ||
13 | b, c = foo() | ||
| ^ F841 | ||
| | ||
= help: Remove assignment to unused variable `b` | ||
|
||
F841_4.py:13:8: F841 Local variable `c` is assigned to but never used | ||
| | ||
11 | def bar(): | ||
12 | a = foo() | ||
13 | b, c = foo() | ||
| ^ F841 | ||
| | ||
= help: Remove assignment to unused variable `c` | ||
|
||
|