astral-sh/ruff · error

Expected an import binding to have a non-empty qualified nam

Error message

Expected an import binding to have a non-empty qualified name; got {qualified_name}

What it means

An unreachable! in ImportBinding::symbol_stored_in_outer_scope: the semantic model produced an import binding whose qualified name is empty, which the rule assumes can never happen because every import binds a non-empty symbol. Firing it signals corrupted semantic data for the import, not a user configuration problem.

Source

Thrown at crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs:547

    scope: ScopeId,
}

impl ImportBinding<'_> {
    /// The symbol that is stored in the outer scope as a result of this import.
    ///
    /// For example:
    /// - `import foo` => `foo` symbol stored in outer scope
    /// - `import foo as bar` => `bar` symbol stored in outer scope
    /// - `from foo import bar` => `bar` symbol stored in outer scope
    /// - `from foo import bar as baz` => `baz` symbol stored in outer scope
    /// - `import foo.bar` => `foo` symbol stored in outer scope
    fn symbol_stored_in_outer_scope(&self) -> &str {
        match &self.import {
            AnyImport::FromImport(_) => self.name,
            AnyImport::Import(_) => self.name,
            AnyImport::SubmoduleImport(SubmoduleImport { qualified_name }) => {
                qualified_name.segments().first().unwrap_or_else(|| {
                    panic!(
                        "Expected an import binding to have a non-empty qualified name;
                        got {qualified_name}"
                    )
                })
            }
        }
    }
}

impl Ranged for ImportBinding<'_> {
    fn range(&self) -> TextRange {
        self.range
    }
}

/// Generate a [`Fix`] to remove unused imports from a statement.
fn fix_by_removing_imports<'a>(
    checker: &Checker,

View on GitHub (pinned to 26f38c119c)

Solutions

  1. Investigate how the binding with an empty qualified name was created in the semantic model
  2. Skip bindings with empty qualified names defensively in the rule
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs:547 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/73de2e25ede6e2ff. Report an issue: GitHub.