Skip to content

Commit

Permalink
[ruff F401 #10390 #10391] add import category to ImportBinding struct
Browse files Browse the repository at this point in the history
  • Loading branch information
plredmond committed Apr 29, 2024
1 parent adc5ecf commit 7614423
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,15 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope, diagnostics: &mut
continue;
};

let Some(category) = categorize(&checker, &import.qualified_name().to_string()) else {
continue;
};

let import = ImportBinding {
import,
range: binding.range(),
parent_range: binding.parent_range(checker.semantic()),
category,
};

if checker.rule_is_ignored(Rule::UnusedImport, import.start())
Expand Down Expand Up @@ -208,6 +213,7 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope, diagnostics: &mut
import,
range,
parent_range,
category,
} in imports
{
let mut diagnostic = Diagnostic::new(
Expand Down Expand Up @@ -242,6 +248,7 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope, diagnostics: &mut
import,
range,
parent_range,
category,
} in ignored.into_values().flatten()
{
let mut diagnostic = Diagnostic::new(
Expand All @@ -268,6 +275,8 @@ struct ImportBinding<'a> {
range: TextRange,
/// The range of the import's parent statement.
parent_range: Option<TextRange>,
/// The origin of the import.
category: ImportType,
}

impl Ranged for ImportBinding<'_> {
Expand Down

0 comments on commit 7614423

Please sign in to comment.