Skip to content

Commit

Permalink
[ruff F401 #10390 #10391] restore the old condition used to enable/di…
Browse files Browse the repository at this point in the history
…sable F401 based on deprecated flag, but use the preview flag; move the testcases down to the preview testcase section; move the insta-snapshots to the preview paths
  • Loading branch information
plredmond committed Apr 30, 2024
1 parent c6a3ef4 commit 5ead877
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/rules/pyflakes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ mod tests {
#[test_case(Rule::UnusedImport, Path::new("F401_21.py"))]
#[test_case(Rule::UnusedImport, Path::new("F401_22.py"))]
#[test_case(Rule::UnusedImport, Path::new("F401_23.py"))]
#[test_case(Rule::UnusedImport, Path::new("F401_24/__init__.py"))]
#[test_case(Rule::UnusedImport, Path::new("F401_25__all/__init__.py"))]
#[test_case(Rule::ImportShadowedByLoopVar, Path::new("F402.py"))]
#[test_case(Rule::ImportShadowedByLoopVar, Path::new("F402.ipynb"))]
#[test_case(Rule::UndefinedLocalWithImportStar, Path::new("F403.py"))]
Expand Down Expand Up @@ -207,6 +205,8 @@ mod tests {
}

#[test_case(Rule::UnusedVariable, Path::new("F841_4.py"))]
#[test_case(Rule::UnusedImport, Path::new("F401_24/__init__.py"))]
#[test_case(Rule::UnusedImport, Path::new("F401_25__all/__init__.py"))]
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!(
"preview__{}_{}",
Expand Down
18 changes: 9 additions & 9 deletions crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope, diagnostics: &mut
}

let in_init = checker.path().ends_with("__init__.py");
let fix_init = checker.settings.preview.is_enabled();
// TODO: find the `__all__` node
let dunder_all = None;

Expand All @@ -211,15 +212,14 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope, diagnostics: &mut
});

// generate fixes that are shared across bindings in the statement
let (fix_remove, fix_explicit) =
if !in_except_handler && checker.settings.preview.is_enabled() {
(
fix_by_removing_imports(checker, import_statement, &to_remove, in_init).ok(),
fix_by_reexporting(checker, import_statement, &to_explicit, dunder_all).ok(),
)
} else {
(None, None)
};
let (fix_remove, fix_explicit) = if (!in_init || fix_init) && !in_except_handler {
(
fix_by_removing_imports(checker, import_statement, &to_remove, in_init).ok(),
fix_by_reexporting(checker, import_statement, &to_explicit, dunder_all).ok(),
)
} else {
(None, None)
};

for (binding, fix) in iter::Iterator::chain(
iter::zip(to_remove, iter::repeat(fix_remove)),
Expand Down

0 comments on commit 5ead877

Please sign in to comment.