Skip to content

Commit e914bc3

Browse files
authored
F401 sort bindings before adding to __all__ (#11648)
Sort the binding IDs before passing them to the add-to-`__all__` function to address #11619.
1 parent 27f6f04 commit e914bc3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope, diagnostics: &mut
330330
fix_by_reexporting(
331331
checker,
332332
import_statement,
333-
&to_reexport.iter().map(|(b, _)| b).collect::<Vec<_>>(),
333+
to_reexport.iter().map(|(b, _)| b).collect::<Vec<_>>(),
334334
&dunder_all_exprs,
335335
)
336336
.ok(),
@@ -450,14 +450,16 @@ fn fix_by_removing_imports<'a>(
450450
fn fix_by_reexporting(
451451
checker: &Checker,
452452
node_id: NodeId,
453-
imports: &[&ImportBinding],
453+
mut imports: Vec<&ImportBinding>,
454454
dunder_all_exprs: &[&ast::Expr],
455455
) -> Result<Fix> {
456456
let statement = checker.semantic().statement(node_id);
457457
if imports.is_empty() {
458458
bail!("Expected import bindings");
459459
}
460460

461+
imports.sort_by_key(|b| b.name);
462+
461463
let edits = match dunder_all_exprs {
462464
[] => fix::edits::make_redundant_alias(
463465
imports.iter().map(|b| b.import.member_name()),

0 commit comments

Comments
 (0)