mirror of https://github.com/astral-sh/ruff
Use `panic` instead of `unreachable` for invalid arguments (#3816)
This commit is contained in:
parent
01357f62e5
commit
0b586d5451
|
|
@ -4735,7 +4735,7 @@ impl<'a> Checker<'a> {
|
|||
);
|
||||
}
|
||||
} else {
|
||||
unreachable!("Expected ExprKind::Lambda");
|
||||
unreachable!("Expected ExprKind::For | ExprKind::AsyncFor");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -512,7 +512,7 @@ pub fn multiple_starts_ends_with(checker: &mut Checker, expr: &Expr) {
|
|||
/// PIE807
|
||||
pub fn reimplemented_list_builtin(checker: &mut Checker, expr: &Expr) {
|
||||
let ExprKind::Lambda { args, body } = &expr.node else {
|
||||
unreachable!("Expected ExprKind::Lambda");
|
||||
panic!("Expected ExprKind::Lambda");
|
||||
};
|
||||
if args.args.is_empty()
|
||||
&& args.kwonlyargs.is_empty()
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ fn reverse_comparison(expr: &Expr, locator: &Locator, stylist: &Stylist) -> Resu
|
|||
whitespace_before,
|
||||
whitespace_after,
|
||||
},
|
||||
_ => unreachable!("Expected comparison operator"),
|
||||
_ => panic!("Expected comparison operator"),
|
||||
};
|
||||
|
||||
let mut state = CodegenState {
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ fn fix_banned_relative_import(
|
|||
};
|
||||
|
||||
let StmtKind::ImportFrom { names, .. } = &stmt.node else {
|
||||
unreachable!("Expected StmtKind::ImportFrom");
|
||||
panic!("Expected StmtKind::ImportFrom");
|
||||
};
|
||||
let content = unparse_stmt(
|
||||
&create_stmt(StmtKind::ImportFrom {
|
||||
|
|
|
|||
|
|
@ -317,6 +317,6 @@ pub fn unused_arguments(
|
|||
vec![]
|
||||
}
|
||||
}
|
||||
_ => unreachable!("Expected ScopeKind::Function | ScopeKind::Lambda"),
|
||||
_ => panic!("Expected ScopeKind::Function | ScopeKind::Lambda"),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ pub fn annotate_imports<'a>(
|
|||
inline,
|
||||
});
|
||||
}
|
||||
_ => unreachable!("Expected StmtKind::Import | StmtKind::ImportFrom"),
|
||||
_ => panic!("Expected StmtKind::Import | StmtKind::ImportFrom"),
|
||||
}
|
||||
}
|
||||
annotated
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ impl From<&Cmpop> for EqCmpop {
|
|||
match cmpop {
|
||||
Cmpop::Eq => EqCmpop::Eq,
|
||||
Cmpop::NotEq => EqCmpop::NotEq,
|
||||
_ => unreachable!("Expected Cmpop::Eq | Cmpop::NotEq"),
|
||||
_ => panic!("Expected Cmpop::Eq | Cmpop::NotEq"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ impl From<&Cmpop> for IsCmpop {
|
|||
match cmpop {
|
||||
Cmpop::Is => IsCmpop::Is,
|
||||
Cmpop::IsNot => IsCmpop::IsNot,
|
||||
_ => unreachable!("Expected Cmpop::Is | Cmpop::IsNot"),
|
||||
_ => panic!("Expected Cmpop::Is | Cmpop::IsNot"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ pub fn yield_outside_function(checker: &mut Checker, expr: &Expr) {
|
|||
ExprKind::Yield { .. } => DeferralKeyword::Yield,
|
||||
ExprKind::YieldFrom { .. } => DeferralKeyword::YieldFrom,
|
||||
ExprKind::Await { .. } => DeferralKeyword::Await,
|
||||
_ => unreachable!("Expected ExprKind::Yield | ExprKind::YieldFrom | ExprKind::Await"),
|
||||
_ => panic!("Expected ExprKind::Yield | ExprKind::YieldFrom | ExprKind::Await"),
|
||||
};
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
YieldOutsideFunction { keyword },
|
||||
|
|
|
|||
|
|
@ -66,6 +66,6 @@ pub fn deprecated_c_element_tree(checker: &mut Checker, stmt: &Stmt) {
|
|||
}
|
||||
}
|
||||
}
|
||||
_ => unreachable!("Expected StmtKind::Import | StmtKind::ImportFrom"),
|
||||
_ => panic!("Expected StmtKind::Import | StmtKind::ImportFrom"),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ fn format_import_from(
|
|||
content
|
||||
})
|
||||
} else {
|
||||
unreachable!("Expected ImportNames::Aliases | ImportNames::Star");
|
||||
panic!("Expected ImportNames::Aliases | ImportNames::Star");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ fn tuple_diagnostic(checker: &mut Checker, target: &Expr, aliases: &[&Expr]) {
|
|||
let mut diagnostic = Diagnostic::new(OSErrorAlias { name: None }, Range::from(target));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let ExprKind::Tuple { elts, ..} = &target.node else {
|
||||
unreachable!("expected ExprKind::Tuple");
|
||||
panic!("Expected ExprKind::Tuple");
|
||||
};
|
||||
|
||||
// Filter out any `OSErrors` aliases.
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ fn collect_names(expr: &Expr) -> Vec<&str> {
|
|||
match &expr.node {
|
||||
ExprKind::Name { id, .. } => vec![id],
|
||||
ExprKind::Tuple { elts, .. } => elts.iter().flat_map(collect_names).collect(),
|
||||
_ => unreachable!("Expected: ExprKind::Name | ExprKind::Tuple"),
|
||||
_ => panic!("Expected: ExprKind::Name | ExprKind::Tuple"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue