astral-sh/ruff · error

Expected ImportNames::Aliases | ImportNames::Star

Error message

Expected ImportNames::Aliases | ImportNames::Star

What it means

An anyhow bail! in the deprecated-mock-import fixer's format_import_from: while rebuilding the import statement, the CST node's import names were neither a list of aliases nor a star, which the fixer's reconstruction logic cannot represent. The fix is abandoned and reported as failed.

Source

Thrown at crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_mock_import.rs:259

                },
                dot: Dot {
                    whitespace_before: ParenthesizableWhitespace::default(),
                    whitespace_after: ParenthesizableWhitespace::default(),
                },
                lpar: vec![],
                rpar: vec![],
            })));

            let mut content = tree.codegen_stylist(stylist);
            if !mock_aliases.is_empty() {
                content.push_str(&stylist.line_ending());
                content.push_str(indent);
                content.push_str(&format_mocks(mock_aliases, indent, stylist));
            }
            content
        })
    } else {
        panic!("Expected ImportNames::Aliases | ImportNames::Star");
    }
}

/// UP026
pub(crate) fn deprecated_mock_attribute(checker: &Checker, attribute: &ast::ExprAttribute) {
    if !checker.semantic().seen_module(Modules::MOCK) {
        return;
    }

    if UnqualifiedName::from_expr(&attribute.value)
        .is_some_and(|qualified_name| matches!(qualified_name.segments(), ["mock", "mock"]))
    {
        let mut diagnostic = checker.report_diagnostic(
            DeprecatedMockImport {
                reference_type: MockReference::Attribute,
            },
            attribute.value.range(),
        );

View on GitHub (pinned to 15f3fe6b15)

Solutions

  1. Extend format_import_from to handle the unexpected ImportNames shape
  2. Skip the autofix when the import form is not reconstructable
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_mock_import.rs:257 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of astral-sh/ruff@15f3fe6b15 (2026-09-05). Data as JSON: /api/errors/ea4b61852c67e58d. Report an issue: GitHub.