From 184f7a30f141669ab543d45e0c8c103b891f305e Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sat, 6 Jan 2024 20:58:27 -0500 Subject: [PATCH] Add a fix for redefinition-while-unused --- .../checkers/ast/analyze/deferred_scopes.rs | 27 +++++++++++++++++-- .../pyflakes/rules/redefined_while_unused.rs | 26 +++++++++++++++++- ...ules__pyflakes__tests__F811_F811_0.py.snap | 1 + ...ules__pyflakes__tests__F811_F811_1.py.snap | 7 ++++- ...les__pyflakes__tests__F811_F811_12.py.snap | 11 +++++++- ...les__pyflakes__tests__F811_F811_15.py.snap | 1 + ...les__pyflakes__tests__F811_F811_16.py.snap | 1 + ...les__pyflakes__tests__F811_F811_17.py.snap | 13 ++++++++- ...ules__pyflakes__tests__F811_F811_2.py.snap | 7 ++++- ...les__pyflakes__tests__F811_F811_21.py.snap | 14 +++++++++- ...les__pyflakes__tests__F811_F811_23.py.snap | 9 ++++++- ...les__pyflakes__tests__F811_F811_26.py.snap | 1 + ...ules__pyflakes__tests__F811_F811_3.py.snap | 1 + ...ules__pyflakes__tests__F811_F811_4.py.snap | 1 + ...ules__pyflakes__tests__F811_F811_5.py.snap | 1 + ...ules__pyflakes__tests__F811_F811_6.py.snap | 10 ++++++- ...ules__pyflakes__tests__F811_F811_8.py.snap | 12 ++++++++- ...shadowed_global_import_in_local_scope.snap | 12 ++++++++- ...shadowed_import_shadow_in_local_scope.snap | 1 + ..._shadowed_local_import_in_local_scope.snap | 12 ++++++++- 20 files changed, 155 insertions(+), 13 deletions(-) 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 4c7a6bd999cd0b..a4dcdea4a300c6 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs @@ -1,10 +1,11 @@ -use ruff_diagnostics::Diagnostic; +use ruff_diagnostics::{Diagnostic, Fix}; use ruff_python_semantic::analyze::visibility; -use ruff_python_semantic::{Binding, BindingKind, ScopeKind}; +use ruff_python_semantic::{Binding, BindingKind, Imported, ScopeKind}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; use crate::codes::Rule; +use crate::fix; use crate::rules::{ flake8_pyi, flake8_type_checking, flake8_unused_arguments, pyflakes, pylint, ruff, }; @@ -247,9 +248,31 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) { }, binding.range(), ); + if let Some(range) = binding.parent_range(&checker.semantic) { 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), + ))) + }); + } + } + diagnostics.push(diagnostic); } } 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 6beceb6addb454..48e8c5038b8574 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 @@ -1,4 +1,4 @@ -use ruff_diagnostics::Violation; +use ruff_diagnostics::{FixAvailability, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_source_file::SourceRow; @@ -22,6 +22,23 @@ 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, @@ -29,9 +46,16 @@ pub struct RedefinedWhileUnused { } impl Violation for RedefinedWhileUnused { + const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; + #[derive_message_formats] fn message(&self) -> String { let RedefinedWhileUnused { name, row } = self; format!("Redefinition of unused `{name}` from {row}") } + + fn fix_title(&self) -> Option { + let RedefinedWhileUnused { name, .. } = self; + Some(format!("Remove definition: `{name}`")) + } } diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_0.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_0.py.snap index 1b8ba23d083eb7..009ba794b77b6b 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_0.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_0.py.snap @@ -7,5 +7,6 @@ F811_0.py:10:5: F811 Redefinition of unused `bar` from line 6 | ^^^ F811 11 | pass | + = help: Remove definition: `bar` 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 196fcfd1c321c0..f83bfbbda14b49 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,10 +1,15 @@ --- 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 3582a992fd0ace..2c52688261660c 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: @@ -9,5 +9,14 @@ F811_12.py:6:20: F811 Redefinition of unused `mixer` from line 2 | ^^^^^ F811 7 | mixer(123) | + = 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_15.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_15.py.snap index ee9654382c523e..7f9b7cca18fee6 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_15.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_15.py.snap @@ -7,5 +7,6 @@ F811_15.py:4:5: F811 Redefinition of unused `fu` from line 1 | ^^ F811 5 | pass | + = help: Remove definition: `fu` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_16.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_16.py.snap index 7a9b81e5e7b67b..ace7efc109b4eb 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_16.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_16.py.snap @@ -9,5 +9,6 @@ F811_16.py:8:13: F811 Redefinition of unused `fu` from line 3 | ^^ F811 9 | pass | + = help: Remove definition: `fu` 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 ebcb6d42a2c9a4..1e5a7b8dfe4ac4 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 @@ -9,6 +9,16 @@ F811_17.py:6:12: F811 Redefinition of unused `fu` from line 2 7 | 8 | def baz(): | + = 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 | @@ -17,5 +27,6 @@ F811_17.py:9:13: F811 Redefinition of unused `fu` from line 6 | ^^ F811 10 | pass | + = help: Remove definition: `fu` 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 c51c3fe03fe933..a4775d009358e7 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,10 +1,15 @@ --- 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 2cf8492603c538..16eb56c29a92e2 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 @@ -9,5 +9,17 @@ F811_21.py:32:5: F811 Redefinition of unused `Sequence` from line 26 | ^^^^^^^^ F811 33 | ) | + = 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 4816ae23e805c2..2b5fe811491127 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,11 +1,18 @@ --- 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 | ^^^ F811 | + = 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_26.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_26.py.snap index 142ee127fd6cfb..a51c892a97937c 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_26.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_26.py.snap @@ -9,5 +9,6 @@ F811_26.py:5:9: F811 Redefinition of unused `func` from line 2 | ^^^^ F811 6 | pass | + = help: Remove definition: `func` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_3.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_3.py.snap index 81d8e6bb5b9760..7e749b088747ad 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_3.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_3.py.snap @@ -6,5 +6,6 @@ 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__F811_F811_4.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_4.py.snap index 0877d0f556a553..0c7c2a4523d791 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_4.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_4.py.snap @@ -6,5 +6,6 @@ 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__F811_F811_5.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_5.py.snap index e6217fbe58fe15..b21d2c3508948b 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_5.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_5.py.snap @@ -6,5 +6,6 @@ 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__F811_F811_6.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_6.py.snap index afb110adb0327b..dbf3fb90254d09 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 @@ -9,5 +9,13 @@ F811_6.py:6:12: F811 Redefinition of unused `os` from line 5 | ^^ F811 7 | os.path | + = 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 9680f0457382a9..9faf3b4b152019 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 @@ -10,5 +10,15 @@ F811_8.py:5:12: F811 Redefinition of unused `os` from line 4 6 | except: 7 | pass | + = 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 85e1d7d06fed04..b1f4839c98c1ba 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 @@ -25,5 +25,15 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs 6 | 7 | # Despite this `del`, `import os` in `f` should still be flagged as shadowing an unused | + = 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_import_shadow_in_local_scope.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_import_shadow_in_local_scope.snap index 8a7530cecd872b..9dfb6527c7f9bb 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_import_shadow_in_local_scope.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_import_shadow_in_local_scope.snap @@ -24,5 +24,6 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ^^ F811 6 | print(os) | + = help: Remove definition: `os` 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 b8807e970a98a3..5cbb230bb69cf4 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 @@ -10,5 +10,15 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs 5 | 6 | # Despite this `del`, `import os` should still be flagged as shadowing an unused | + = 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.