F401 sort bindings before adding to __all__ (#11648)

Sort the binding IDs before passing them to the add-to-`__all__`
function to address #11619.
This commit is contained in:
plredmond 2024-05-31 13:29:08 -07:00 committed by GitHub
parent 27f6f048f0
commit e914bc300b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 2 deletions

View File

@ -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(),
@ -450,7 +450,7 @@ 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);
@ -458,6 +458,8 @@ fn fix_by_reexporting(
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()),