astral-sh/ruff · error
Required import specified in `lint.isort.required-imports`…
Error message
Required import specified in `lint.isort.required-imports` (I002) conflicts with the required import alias specified in either `lint.flake8-import-conventions.aliases` or `lint.flake8-import-conventions.extend-aliases` (ICN001):
{err_body}
Help: Remove the required import or alias from your configuration. What it means
Error "Required import specified in `lint.isort.required-imports` (I002) conflicts with the required import alias specified in either `lint.flake8-import-conventions.aliases` or `lint.flake8-import-conventions.extend-aliases` (ICN001): {err_body} Help: Remove the required import or alias from your configuration." thrown in astral-sh/ruff.
Solutions
- Remove the alias from flake8-import-conventions settings so it no longer conflicts with the required import
- Rewrite the I002 required-import to use the same alias as the conventions setting
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/ruff_workspace/src/configuration.rs:1778 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of astral-sh/ruff@26f38c119c (2026-09-05).
Data as JSON: /api/errors/40869455255ca41a.
Report an issue: GitHub.
Appendix: source
Thrown at crates/ruff_workspace/src/configuration.rs:1778
// Ex: `from foo import bar as baz` OR `import foo.bar as baz`
// - qualified name: `foo.bar`
// - bound name: `baz`
// - conflicts with: `{"foo.bar":"buzz"}`
// - does not conflict with either of
// - `{"bar":"buzz"}`
// - `{"foo.bar":"baz"}`
let qualified_name = required_import.qualified_name().to_string();
let bound_name = required_import.bound_name();
let Some(alias) = flake8_import_conventions.aliases.get(&qualified_name) else {
continue;
};
if alias != bound_name {
writeln!(err_body, " - `{qualified_name}` -> `{alias}`").unwrap();
}
}
if !err_body.is_empty() {
return Err(anyhow!(
"Required import specified in `lint.isort.required-imports` (I002) \
conflicts with the required import alias specified in either \
`lint.flake8-import-conventions.aliases` or \
`lint.flake8-import-conventions.extend-aliases` (ICN001):\
\n{err_body}\n\
Help: Remove the required import or alias from your configuration."
));
}
Ok(())
}
/// Detect conflicts between I002 (missing-required-import) and PYI025
/// (unaliased-collections-abc-set-import).
///
/// If `required-imports` includes `from collections.abc import Set` (without
/// aliasing it as `AbstractSet`) and PYI025 is enabled, the configuration is
/// contradictory: I002 requires the unaliased import, while PYI025 forbids it.View on GitHub (pinned to 26f38c119c)