astral-sh/ruff · error
Expected comparison operator
Error message
Expected comparison operator
What it means
An unreachable! in reverse_comparison (used by the yoda-conditions fixer): the CST comparison operator being rewritten is not one of the operators the fixer knows how to flip. Since the caller already validated the expression, hitting this arm indicates a mismatch between detection and fixing logic.
Source
Thrown at crates/ruff_linter/src/rules/flake8_simplify/rules/yoda_conditions.rs:199
} => CompOp::LessThanEqual {
whitespace_before: or_space(whitespace_before),
whitespace_after: or_space(whitespace_after),
},
CompOp::Equal {
whitespace_before,
whitespace_after,
} => CompOp::Equal {
whitespace_before: or_space(whitespace_before),
whitespace_after: or_space(whitespace_after),
},
CompOp::NotEqual {
whitespace_before,
whitespace_after,
} => CompOp::NotEqual {
whitespace_before: or_space(whitespace_before),
whitespace_after: or_space(whitespace_after),
},
_ => panic!("Expected comparison operator"),
};
Ok(expression)
})
}
/// SIM300
pub(crate) fn yoda_conditions(checker: &Checker, compare: &ast::ExprCompare) {
let Some((left, op, right)) = compare.as_single() else {
return;
};
if !matches!(
op,
CmpOp::Eq | CmpOp::NotEq | CmpOp::Lt | CmpOp::LtE | CmpOp::Gt | CmpOp::GtE,
) {
return;
}View on GitHub (pinned to 15f3fe6b15)
Solutions
- Add a match arm for the missing operator in reverse_comparison
- Restrict the rule trigger to operators the fixer supports
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at crates/ruff_linter/src/rules/flake8_simplify/rules/yoda_conditions.rs:200 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/000fab9861e10496.
Report an issue: GitHub.