Skip to content

Commit

Permalink
[ruff F401 #10390 #10391] rename and adjust new "fix_imports" function
Browse files Browse the repository at this point in the history
  • Loading branch information
plredmond committed Apr 26, 2024
1 parent a9eb18e commit 73fc61c
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,42 +334,31 @@ fn fix_by_removing_imports(
)
}

/// Generate a [`Fix`] to make bindings in a statement explicit, either by moving them to `__all__`
/// Generate a [`Fix`] to make bindings in a statement explicit, either by adding them to `__all__`
/// or changing them from `import a` to `import a as a`.
fn fix_by_reexporting(
checker: &Checker,
node_id: NodeId,
imports: &[ImportBinding],
export_list: Option<NodeId>,
dunder_all: Option<NodeId>,
) -> Option<Fix> {
let statement = checker.semantic().statement(node_id);
let parent = checker.semantic().parent_statement(node_id);

let member_names = imports
.iter()
.map(|binding| binding.import.member_name())
.collect::<Vec<_>>();
let member_names = member_names.iter().map(AsRef::as_ref);

// if export_list:NodeId is given, generate edits to remove from the import AND edits to add to
// __all__ and combine them into a single fix
let edits = match export_list {
Some(export_list) => {
// TODO: generate explicits by writing an edit function using `export_list` argument
//fix::edits::make_exports_explicit(explicits, export_list)
todo!()
}
// TODO: double check that this doesn't emit an edit when the list is empty
None => fix::edits::make_imports_explicit(
member_names.iter().map(AsRef::as_ref),
statement,
checker.locator(),
),
let edits = match dunder_all {
Some(dunder_all) => todo!(),
None => fix::edits::make_redundant_alias(member_names, statement),
};

// Only emit a fix if there are edits
let [_head, _tail @ ..] = &edits[..] else {
if 0 == edits.len() || 0 < imports.len() {
return None;
};
}
let mut edits_iter = edits.into_iter();
let first = edits_iter.next()?;

Expand Down

0 comments on commit 73fc61c

Please sign in to comment.