Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use ruff_text_size::Ranged;
use crate::checkers::ast::Checker;
use crate::fix;
use crate::{AlwaysFixableViolation, Applicability, Fix};
use ruff_python_semantic::{MemberNameImport, ModuleNameImport, NameImport};

/// ## What it does
/// Checks for unnecessary `__future__` imports.
Expand Down Expand Up @@ -91,6 +92,44 @@ pub(crate) fn unnecessary_future_import(checker: &Checker, stmt: &Stmt, names: &
if alias.asname.is_some() {
continue;
}
let is_required = match stmt {
ruff_python_ast::Stmt::ImportFrom(ruff_python_ast::StmtImportFrom {
module,
level,
..
}) => {
let name_import = NameImport::ImportFrom(MemberNameImport {
module: module.as_ref().map(std::string::ToString::to_string),
name: ruff_python_semantic::Alias {
name: alias.name.to_string(),
as_name: None,
},
level: *level,
});
checker
.settings()
.isort
.required_imports
.contains(&name_import)
}
ruff_python_ast::Stmt::Import(_) => {
let name_import = NameImport::Import(ModuleNameImport {
name: ruff_python_semantic::Alias {
name: alias.name.to_string(),
as_name: None,
},
});
checker
.settings()
.isort
.required_imports
.contains(&name_import)
}
_ => false,
};
if is_required {
continue;
}
if PY33_PLUS_REMOVE_FUTURES.contains(&alias.name.as_str())
|| PY37_PLUS_REMOVE_FUTURES.contains(&alias.name.as_str())
{
Expand Down
Loading