Skip to content

Commit

Permalink
Wrap the only expr in the vector instead of panic
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Jul 12, 2023
1 parent a93276e commit 2ef8500
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions crates/ruff/src/rules/ruff/typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,12 @@ fn is_known_type(call_path: &CallPath, minor_version: u32) -> bool {
}
}

/// Returns a vector of all the expressions in a slice.
///
/// ## Panics
///
/// Panics if the slice is not a tuple or a constant. This should never happen
/// as this function is only used in typing context where the slice cannot be
/// anything else.
/// Returns a vector of all the expressions in a slice. If the slice is not a
/// tuple, it will be wrapped in a vector.
fn resolve_slice_value(slice: &Expr) -> Vec<&Expr> {
match slice {
Expr::Tuple(ast::ExprTuple { elts: elements, .. }) => elements.iter().collect(),
Expr::Constant(_) => vec![slice],
_ => unreachable!("type slice must be a tuple or a constant"),
_ => vec![slice],
}
}

Expand Down

0 comments on commit 2ef8500

Please sign in to comment.