Skip to content

Commit

Permalink
F401 sort bindings before adding to __all__ (#11648)
Browse files Browse the repository at this point in the history
Sort the binding IDs before passing them to the add-to-`__all__`
function to address #11619.
  • Loading branch information
plredmond committed May 31, 2024
1 parent 27f6f04 commit e914bc3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope, diagnostics: &mut
fix_by_reexporting(
checker,
import_statement,
&to_reexport.iter().map(|(b, _)| b).collect::<Vec<_>>(),
to_reexport.iter().map(|(b, _)| b).collect::<Vec<_>>(),
&dunder_all_exprs,
)
.ok(),
Expand Down Expand Up @@ -450,14 +450,16 @@ fn fix_by_removing_imports<'a>(
fn fix_by_reexporting(
checker: &Checker,
node_id: NodeId,
imports: &[&ImportBinding],
mut imports: Vec<&ImportBinding>,
dunder_all_exprs: &[&ast::Expr],
) -> Result<Fix> {
let statement = checker.semantic().statement(node_id);
if imports.is_empty() {
bail!("Expected import bindings");
}

imports.sort_by_key(|b| b.name);

let edits = match dunder_all_exprs {
[] => fix::edits::make_redundant_alias(
imports.iter().map(|b| b.import.member_name()),
Expand Down

0 comments on commit e914bc3

Please sign in to comment.