-
Notifications
You must be signed in to change notification settings - Fork 943
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a fix for
redefinition-while-unused
(#9419)
## Summary This PR enables Ruff to remove redefined imports, as in: ```python import os import os print(os) ``` Previously, Ruff would flag `F811` on the second `import os`, but couldn't fix it. For now, this fix is marked as safe, but only available in preview. Closes #3477.
- Loading branch information
1 parent
985f1d1
commit 84ab21f
Showing
49 changed files
with
391 additions
and
3 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
|
@@ -7,5 +7,6 @@ F811_15.py:4:5: F811 Redefinition of unused `fu` from line 1 | |
| ^^ F811 | ||
5 | pass | ||
| | ||
= help: Remove definition: `fu` | ||
|
||
|
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
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
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
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
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 |
---|---|---|
|
@@ -24,5 +24,6 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs | |
| ^^ F811 | ||
6 | print(os) | ||
| | ||
= help: Remove definition: `os` | ||
|
||
|
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
12 changes: 12 additions & 0 deletions
12
...ules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_0.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,12 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
--- | ||
F811_0.py:10:5: F811 Redefinition of unused `bar` from line 6 | ||
| | ||
10 | def bar(): | ||
| ^^^ F811 | ||
11 | pass | ||
| | ||
= help: Remove definition: `bar` | ||
|
||
|
15 changes: 15 additions & 0 deletions
15
...ules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_1.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,15 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
--- | ||
F811_1.py:1:25: F811 [*] Redefinition of unused `FU` from line 1 | ||
| | ||
1 | import fu as FU, bar as FU | ||
| ^^ F811 | ||
| | ||
= help: Remove definition: `FU` | ||
|
||
ℹ Safe fix | ||
1 |-import fu as FU, bar as FU | ||
1 |+import fu as FU | ||
|
||
|
4 changes: 4 additions & 0 deletions
4
...les/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_10.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,4 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
--- | ||
|
4 changes: 4 additions & 0 deletions
4
...les/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_11.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,4 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
--- | ||
|
22 changes: 22 additions & 0 deletions
22
...les/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_12.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,22 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
--- | ||
F811_12.py:6:20: F811 [*] Redefinition of unused `mixer` from line 2 | ||
| | ||
4 | pass | ||
5 | else: | ||
6 | from bb import mixer | ||
| ^^^^^ F811 | ||
7 | mixer(123) | ||
| | ||
= help: Remove definition: `mixer` | ||
|
||
ℹ Safe fix | ||
3 3 | except ImportError: | ||
4 4 | pass | ||
5 5 | else: | ||
6 |- from bb import mixer | ||
6 |+ pass | ||
7 7 | mixer(123) | ||
|
||
|
4 changes: 4 additions & 0 deletions
4
...les/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_13.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,4 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
--- | ||
|
4 changes: 4 additions & 0 deletions
4
...les/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_14.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,4 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
--- | ||
|
12 changes: 12 additions & 0 deletions
12
...les/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_15.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,12 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
--- | ||
F811_15.py:4:5: F811 Redefinition of unused `fu` from line 1 | ||
| | ||
4 | def fu(): | ||
| ^^ F811 | ||
5 | pass | ||
| | ||
= help: Remove definition: `fu` | ||
|
||
|
14 changes: 14 additions & 0 deletions
14
...les/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_16.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,14 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
--- | ||
F811_16.py:8:13: F811 Redefinition of unused `fu` from line 3 | ||
| | ||
6 | def bar(): | ||
7 | def baz(): | ||
8 | def fu(): | ||
| ^^ F811 | ||
9 | pass | ||
| | ||
= help: Remove definition: `fu` | ||
|
||
|
32 changes: 32 additions & 0 deletions
32
...les/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_17.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,32 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
--- | ||
F811_17.py:6:12: F811 [*] Redefinition of unused `fu` from line 2 | ||
| | ||
5 | def bar(): | ||
6 | import fu | ||
| ^^ F811 | ||
7 | | ||
8 | def baz(): | ||
| | ||
= help: Remove definition: `fu` | ||
|
||
ℹ Safe fix | ||
3 3 | | ||
4 4 | | ||
5 5 | def bar(): | ||
6 |- import fu | ||
7 6 | | ||
8 7 | def baz(): | ||
9 8 | def fu(): | ||
|
||
F811_17.py:9:13: F811 Redefinition of unused `fu` from line 6 | ||
| | ||
8 | def baz(): | ||
9 | def fu(): | ||
| ^^ F811 | ||
10 | pass | ||
| | ||
= help: Remove definition: `fu` | ||
|
||
|
4 changes: 4 additions & 0 deletions
4
...les/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_18.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,4 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
--- | ||
|
4 changes: 4 additions & 0 deletions
4
...les/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_19.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,4 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
--- | ||
|
15 changes: 15 additions & 0 deletions
15
...ules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_2.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,15 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
--- | ||
F811_2.py:1:34: F811 [*] Redefinition of unused `FU` from line 1 | ||
| | ||
1 | from moo import fu as FU, bar as FU | ||
| ^^ F811 | ||
| | ||
= help: Remove definition: `FU` | ||
|
||
ℹ Safe fix | ||
1 |-from moo import fu as FU, bar as FU | ||
1 |+from moo import fu as FU | ||
|
||
|
Oops, something went wrong.