-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically remove unused variables (#1683)
Closes #1460.
- Loading branch information
1 parent
d5256f8
commit 0527fb9
Showing
16 changed files
with
666 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Test case for autofixing F841 violations.""" | ||
|
||
|
||
def f(): | ||
x = 1 | ||
y = 2 | ||
|
||
z = 3 | ||
print(z) | ||
|
||
|
||
def f(): | ||
x: int = 1 | ||
y: int = 2 | ||
|
||
z: int = 3 | ||
print(z) | ||
|
||
|
||
def f(): | ||
with foo() as x1: | ||
pass | ||
|
||
with foo() as (x2, y2): | ||
pass | ||
|
||
with (foo() as x3, foo() as y3, foo() as z3): | ||
pass | ||
|
||
|
||
def f(): | ||
(x1, y1) = (1, 2) | ||
(x2, y2) = coords2 = (1, 2) | ||
coords3 = (x3, y3) = (1, 2) | ||
|
||
|
||
def f(): | ||
try: | ||
1 / 0 | ||
except ValueError as x1: | ||
pass | ||
|
||
try: | ||
1 / 0 | ||
except (ValueError, ZeroDivisionError) as x2: | ||
pass |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use crate::ast::types::BindingKind; | ||
use crate::checkers::ast::Checker; | ||
use crate::registry::{Check, CheckKind}; | ||
|
||
/// F842 | ||
pub fn unused_annotation(checker: &mut Checker, scope: usize) { | ||
let scope = &checker.scopes[scope]; | ||
for (name, binding) in scope | ||
.values | ||
.iter() | ||
.map(|(name, index)| (name, &checker.bindings[*index])) | ||
{ | ||
if binding.used.is_none() | ||
&& matches!(binding.kind, BindingKind::Annotation) | ||
&& !checker.settings.dummy_variable_rgx.is_match(name) | ||
{ | ||
checker.checks.push(Check::new( | ||
CheckKind::UnusedAnnotation((*name).to_string()), | ||
binding.range, | ||
)); | ||
} | ||
} | ||
} |
Oops, something went wrong.