diff --git a/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs b/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs index 6062befcae80f..e6c46334dd7af 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs @@ -253,23 +253,25 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) { diagnostic.set_parent(range.start()); } - if let Some(import) = binding.as_any_import() { - if let Some(source) = binding.source { - diagnostic.try_set_fix(|| { - let statement = checker.semantic().statement(source); - let parent = checker.semantic().parent_statement(source); - let edit = fix::edits::remove_unused_imports( - std::iter::once(import.member_name().as_ref()), - statement, - parent, - checker.locator(), - checker.stylist(), - checker.indexer(), - )?; - Ok(Fix::unsafe_edit(edit).isolate(Checker::isolation( - checker.semantic().parent_statement_id(source), - ))) - }); + if checker.settings.preview.is_enabled() { + if let Some(import) = binding.as_any_import() { + if let Some(source) = binding.source { + diagnostic.try_set_fix(|| { + let statement = checker.semantic().statement(source); + let parent = checker.semantic().parent_statement(source); + let edit = fix::edits::remove_unused_imports( + std::iter::once(import.member_name().as_ref()), + statement, + parent, + checker.locator(), + checker.stylist(), + checker.indexer(), + )?; + Ok(Fix::safe_edit(edit).isolate(Checker::isolation( + checker.semantic().parent_statement_id(source), + ))) + }); + } } } diff --git a/crates/ruff_linter/src/rules/pyflakes/mod.rs b/crates/ruff_linter/src/rules/pyflakes/mod.rs index 6f9ad095718bb..1645fb8ec9e12 100644 --- a/crates/ruff_linter/src/rules/pyflakes/mod.rs +++ b/crates/ruff_linter/src/rules/pyflakes/mod.rs @@ -168,6 +168,34 @@ mod tests { Ok(()) } + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_0.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_1.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_10.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_11.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_12.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_13.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_14.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_15.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_16.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_17.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_18.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_19.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_2.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_20.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_21.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_22.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_23.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_24.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_25.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_26.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_27.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_3.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_4.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_5.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_6.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_7.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_8.py"))] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_9.py"))] #[test_case(Rule::UnusedVariable, Path::new("F841_4.py"))] fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> { let snapshot = format!( diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/redefined_while_unused.rs b/crates/ruff_linter/src/rules/pyflakes/rules/redefined_while_unused.rs index 48e8c5038b857..f65090d328b6d 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/redefined_while_unused.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/redefined_while_unused.rs @@ -22,23 +22,6 @@ use ruff_source_file::SourceRow; /// import foo /// import bar /// ``` -/// -/// ## Fix safety -/// This rule's fix is marked as unsafe, as removing a redefinition across -/// branches or scopes may change the behavior of the program in subtle -/// ways. -/// -/// For example: -/// ```python -/// import module -/// -/// x = int(input()) -/// -/// if x > 0: -/// from package import module -/// ``` -/// -/// Removing the redefinition would change the `module` binding when `x > 0`. #[violation] pub struct RedefinedWhileUnused { pub name: String, diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_1.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_1.py.snap index f83bfbbda14b4..3c5023ea35e37 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_1.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_1.py.snap @@ -1,15 +1,11 @@ --- source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- -F811_1.py:1:25: F811 [*] Redefinition of unused `FU` from line 1 +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` -ℹ Unsafe fix -1 |-import fu as FU, bar as FU - 1 |+import fu as FU - diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_12.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_12.py.snap index 2c52688261660..ccc34ca245585 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_12.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_12.py.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- -F811_12.py:6:20: F811 [*] Redefinition of unused `mixer` from line 2 +F811_12.py:6:20: F811 Redefinition of unused `mixer` from line 2 | 4 | pass 5 | else: @@ -11,12 +11,4 @@ F811_12.py:6:20: F811 [*] Redefinition of unused `mixer` from line 2 | = help: Remove definition: `mixer` -ℹ Unsafe fix -3 3 | except ImportError: -4 4 | pass -5 5 | else: -6 |- from bb import mixer - 6 |+ pass -7 7 | mixer(123) - diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_17.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_17.py.snap index 1e5a7b8dfe4ac..d6a499c088e44 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_17.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_17.py.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- -F811_17.py:6:12: F811 [*] Redefinition of unused `fu` from line 2 +F811_17.py:6:12: F811 Redefinition of unused `fu` from line 2 | 5 | def bar(): 6 | import fu @@ -11,15 +11,6 @@ F811_17.py:6:12: F811 [*] Redefinition of unused `fu` from line 2 | = help: Remove definition: `fu` -ℹ Unsafe 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(): diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_2.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_2.py.snap index a4775d009358e..78c4a39f1cbed 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_2.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_2.py.snap @@ -1,15 +1,11 @@ --- source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- -F811_2.py:1:34: F811 [*] Redefinition of unused `FU` from line 1 +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` -ℹ Unsafe fix -1 |-from moo import fu as FU, bar as FU - 1 |+from moo import fu as FU - diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_21.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_21.py.snap index 16eb56c29a92e..48525af0fd19a 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_21.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_21.py.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- -F811_21.py:32:5: F811 [*] Redefinition of unused `Sequence` from line 26 +F811_21.py:32:5: F811 Redefinition of unused `Sequence` from line 26 | 30 | from typing import ( 31 | List, # noqa: F811 @@ -11,15 +11,4 @@ F811_21.py:32:5: F811 [*] Redefinition of unused `Sequence` from line 26 | = help: Remove definition: `Sequence` -ℹ Unsafe fix -29 29 | # This should ignore the first error. -30 30 | from typing import ( -31 31 | List, # noqa: F811 -32 |- Sequence, -33 |-) - 32 |+ ) -34 33 | -35 34 | # This should ignore both errors. -36 35 | from typing import ( # noqa - diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_23.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_23.py.snap index 2b5fe81149112..b4996ebf10b34 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_23.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_23.py.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- -F811_23.py:4:15: F811 [*] Redefinition of unused `foo` from line 3 +F811_23.py:4:15: F811 Redefinition of unused `foo` from line 3 | 3 | import foo as foo 4 | import bar as foo @@ -9,10 +9,4 @@ F811_23.py:4:15: F811 [*] Redefinition of unused `foo` from line 3 | = help: Remove definition: `foo` -ℹ Unsafe fix -1 1 | """Test that shadowing an explicit re-export produces a warning.""" -2 2 | -3 3 | import foo as foo -4 |-import bar as foo - diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_6.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_6.py.snap index dbf3fb90254d0..a246b2275d0b5 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_6.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_6.py.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- -F811_6.py:6:12: F811 [*] Redefinition of unused `os` from line 5 +F811_6.py:6:12: F811 Redefinition of unused `os` from line 5 | 4 | if i == 1: 5 | import os @@ -11,11 +11,4 @@ F811_6.py:6:12: F811 [*] Redefinition of unused `os` from line 5 | = help: Remove definition: `os` -ℹ Unsafe fix -3 3 | i = 2 -4 4 | if i == 1: -5 5 | import os -6 |- import os -7 6 | os.path - diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_8.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_8.py.snap index 9faf3b4b15201..86799a2aaf7cc 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_8.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_8.py.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- -F811_8.py:5:12: F811 [*] Redefinition of unused `os` from line 4 +F811_8.py:5:12: F811 Redefinition of unused `os` from line 4 | 3 | try: 4 | import os @@ -12,13 +12,4 @@ F811_8.py:5:12: F811 [*] Redefinition of unused `os` from line 4 | = help: Remove definition: `os` -ℹ Unsafe fix -2 2 | -3 3 | try: -4 4 | import os -5 |- import os -6 5 | except: -7 6 | pass -8 7 | os.path - diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_global_import_in_local_scope.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_global_import_in_local_scope.snap index b1f4839c98c1b..844c9a7cba6ff 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_global_import_in_local_scope.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_global_import_in_local_scope.snap @@ -17,7 +17,7 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs 4 3 | def f(): 5 4 | import os -:5:12: F811 [*] Redefinition of unused `os` from line 2 +:5:12: F811 Redefinition of unused `os` from line 2 | 4 | def f(): 5 | import os @@ -27,13 +27,4 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs | = help: Remove definition: `os` -ℹ Unsafe fix -2 2 | import os -3 3 | -4 4 | def f(): -5 |- import os -6 5 | -7 6 | # Despite this `del`, `import os` in `f` should still be flagged as shadowing an unused -8 7 | # import. - diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_local_import_in_local_scope.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_local_import_in_local_scope.snap index 5cbb230bb69cf..97a806998dc7f 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_local_import_in_local_scope.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_local_import_in_local_scope.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- -:4:12: F811 [*] Redefinition of unused `os` from line 3 +:4:12: F811 Redefinition of unused `os` from line 3 | 2 | def f(): 3 | import os @@ -12,13 +12,4 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs | = help: Remove definition: `os` -ℹ Unsafe fix -1 1 | -2 2 | def f(): -3 3 | import os -4 |- import os -5 4 | -6 5 | # Despite this `del`, `import os` should still be flagged as shadowing an unused -7 6 | # import. - diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_0.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_0.py.snap new file mode 100644 index 0000000000000..009ba794b77b6 --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_0.py.snap @@ -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` + + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_1.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_1.py.snap new file mode 100644 index 0000000000000..b3d2ebd453667 --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_1.py.snap @@ -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 + + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_10.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_10.py.snap new file mode 100644 index 0000000000000..d0b409f39ee0b --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_10.py.snap @@ -0,0 +1,4 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_11.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_11.py.snap new file mode 100644 index 0000000000000..d0b409f39ee0b --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_11.py.snap @@ -0,0 +1,4 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_12.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_12.py.snap new file mode 100644 index 0000000000000..1411fddf047c7 --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_12.py.snap @@ -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) + + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_13.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_13.py.snap new file mode 100644 index 0000000000000..d0b409f39ee0b --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_13.py.snap @@ -0,0 +1,4 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_14.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_14.py.snap new file mode 100644 index 0000000000000..d0b409f39ee0b --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_14.py.snap @@ -0,0 +1,4 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_15.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_15.py.snap new file mode 100644 index 0000000000000..7f9b7cca18fee --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_15.py.snap @@ -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` + + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_16.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_16.py.snap new file mode 100644 index 0000000000000..ace7efc109b4e --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_16.py.snap @@ -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` + + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_17.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_17.py.snap new file mode 100644 index 0000000000000..b2e62e8597fb6 --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_17.py.snap @@ -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` + + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_18.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_18.py.snap new file mode 100644 index 0000000000000..d0b409f39ee0b --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_18.py.snap @@ -0,0 +1,4 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_19.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_19.py.snap new file mode 100644 index 0000000000000..d0b409f39ee0b --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_19.py.snap @@ -0,0 +1,4 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_2.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_2.py.snap new file mode 100644 index 0000000000000..9e87d29c8d81e --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_2.py.snap @@ -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 + + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_20.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_20.py.snap new file mode 100644 index 0000000000000..d0b409f39ee0b --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_20.py.snap @@ -0,0 +1,4 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_21.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_21.py.snap new file mode 100644 index 0000000000000..6d0405c66f566 --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_21.py.snap @@ -0,0 +1,25 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- +F811_21.py:32:5: F811 [*] Redefinition of unused `Sequence` from line 26 + | +30 | from typing import ( +31 | List, # noqa: F811 +32 | Sequence, + | ^^^^^^^^ F811 +33 | ) + | + = help: Remove definition: `Sequence` + +ℹ Safe fix +29 29 | # This should ignore the first error. +30 30 | from typing import ( +31 31 | List, # noqa: F811 +32 |- Sequence, +33 |-) + 32 |+ ) +34 33 | +35 34 | # This should ignore both errors. +36 35 | from typing import ( # noqa + + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_22.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_22.py.snap new file mode 100644 index 0000000000000..d0b409f39ee0b --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_22.py.snap @@ -0,0 +1,4 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_23.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_23.py.snap new file mode 100644 index 0000000000000..d03de5d32f98b --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_23.py.snap @@ -0,0 +1,18 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- +F811_23.py:4:15: F811 [*] Redefinition of unused `foo` from line 3 + | +3 | import foo as foo +4 | import bar as foo + | ^^^ F811 + | + = help: Remove definition: `foo` + +ℹ Safe fix +1 1 | """Test that shadowing an explicit re-export produces a warning.""" +2 2 | +3 3 | import foo as foo +4 |-import bar as foo + + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_24.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_24.py.snap new file mode 100644 index 0000000000000..d0b409f39ee0b --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_24.py.snap @@ -0,0 +1,4 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_25.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_25.py.snap new file mode 100644 index 0000000000000..d0b409f39ee0b --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_25.py.snap @@ -0,0 +1,4 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_26.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_26.py.snap new file mode 100644 index 0000000000000..a51c892a97937 --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_26.py.snap @@ -0,0 +1,14 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- +F811_26.py:5:9: F811 Redefinition of unused `func` from line 2 + | +3 | pass +4 | +5 | def func(self): + | ^^^^ F811 +6 | pass + | + = help: Remove definition: `func` + + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_27.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_27.py.snap new file mode 100644 index 0000000000000..d0b409f39ee0b --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_27.py.snap @@ -0,0 +1,4 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_3.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_3.py.snap new file mode 100644 index 0000000000000..7e749b088747a --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_3.py.snap @@ -0,0 +1,11 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- +F811_3.py:1:12: F811 Redefinition of unused `fu` from line 1 + | +1 | import fu; fu = 3 + | ^^ F811 + | + = help: Remove definition: `fu` + + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_4.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_4.py.snap new file mode 100644 index 0000000000000..0c7c2a4523d79 --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_4.py.snap @@ -0,0 +1,11 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- +F811_4.py:1:12: F811 Redefinition of unused `fu` from line 1 + | +1 | import fu; fu, bar = 3 + | ^^ F811 + | + = help: Remove definition: `fu` + + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_5.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_5.py.snap new file mode 100644 index 0000000000000..b21d2c3508948 --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_5.py.snap @@ -0,0 +1,11 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- +F811_5.py:1:13: F811 Redefinition of unused `fu` from line 1 + | +1 | import fu; [fu, bar] = 3 + | ^^ F811 + | + = help: Remove definition: `fu` + + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_6.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_6.py.snap new file mode 100644 index 0000000000000..92fc67263100e --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_6.py.snap @@ -0,0 +1,21 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- +F811_6.py:6:12: F811 [*] Redefinition of unused `os` from line 5 + | +4 | if i == 1: +5 | import os +6 | import os + | ^^ F811 +7 | os.path + | + = help: Remove definition: `os` + +ℹ Safe fix +3 3 | i = 2 +4 4 | if i == 1: +5 5 | import os +6 |- import os +7 6 | os.path + + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_7.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_7.py.snap new file mode 100644 index 0000000000000..d0b409f39ee0b --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_7.py.snap @@ -0,0 +1,4 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_8.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_8.py.snap new file mode 100644 index 0000000000000..07e8aeb1e6324 --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_8.py.snap @@ -0,0 +1,24 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- +F811_8.py:5:12: F811 [*] Redefinition of unused `os` from line 4 + | +3 | try: +4 | import os +5 | import os + | ^^ F811 +6 | except: +7 | pass + | + = help: Remove definition: `os` + +ℹ Safe fix +2 2 | +3 3 | try: +4 4 | import os +5 |- import os +6 5 | except: +7 6 | pass +8 7 | os.path + + diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_9.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_9.py.snap new file mode 100644 index 0000000000000..d0b409f39ee0b --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F811_F811_9.py.snap @@ -0,0 +1,4 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- +