mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
Use Expr::is_* methods at more call sites (#5075)
This commit is contained in:
parent
4d9b0b925d
commit
fc6580592d
6 changed files with 13 additions and 17 deletions
|
@ -59,7 +59,7 @@ pub(crate) fn starred_expressions(
|
|||
let mut has_starred: bool = false;
|
||||
let mut starred_index: Option<usize> = None;
|
||||
for (index, elt) in elts.iter().enumerate() {
|
||||
if matches!(elt, Expr::Starred(_)) {
|
||||
if elt.is_starred_expr() {
|
||||
if has_starred && check_two_starred_expressions {
|
||||
return Some(Diagnostic::new(MultipleStarredExpressions, location));
|
||||
}
|
||||
|
|
|
@ -514,14 +514,13 @@ impl Violation for StringDotFormatMixingAutomatic {
|
|||
}
|
||||
|
||||
fn has_star_star_kwargs(keywords: &[Keyword]) -> bool {
|
||||
keywords.iter().any(|k| {
|
||||
let Keyword { arg, .. } = &k;
|
||||
arg.is_none()
|
||||
})
|
||||
keywords
|
||||
.iter()
|
||||
.any(|keyword| matches!(keyword, Keyword { arg: None, .. }))
|
||||
}
|
||||
|
||||
fn has_star_args(args: &[Expr]) -> bool {
|
||||
args.iter().any(|arg| matches!(&arg, Expr::Starred(_)))
|
||||
args.iter().any(Expr::is_starred_expr)
|
||||
}
|
||||
|
||||
/// F502
|
||||
|
@ -805,9 +804,7 @@ pub(crate) fn string_dot_format_extra_positional_arguments(
|
|||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(i, arg)| {
|
||||
!(matches!(arg, Expr::Starred(_))
|
||||
|| summary.autos.contains(i)
|
||||
|| summary.indices.contains(i))
|
||||
!(arg.is_starred_expr() || summary.autos.contains(i) || summary.indices.contains(i))
|
||||
})
|
||||
.map(|(i, _)| i)
|
||||
.collect();
|
||||
|
|
|
@ -93,7 +93,7 @@ pub(crate) fn logging_call(
|
|||
keywords: &[Keyword],
|
||||
) {
|
||||
// If there are any starred arguments, abort.
|
||||
if args.iter().any(|arg| matches!(arg, Expr::Starred(_))) {
|
||||
if args.iter().any(Expr::is_starred_expr) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -85,14 +85,13 @@ pub(crate) fn use_pep604_isinstance(
|
|||
}
|
||||
|
||||
// Ex) `(*args,)`
|
||||
if elts.iter().any(|elt| matches!(elt, Expr::Starred(_))) {
|
||||
if elts.iter().any(Expr::is_starred_expr) {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut diagnostic = Diagnostic::new(NonPEP604Isinstance { kind }, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
checker.generator().expr(&union(elts)),
|
||||
types.range(),
|
||||
)));
|
||||
|
|
|
@ -115,7 +115,7 @@ pub(crate) fn pairwise_over_zipped(checker: &mut Checker, func: &Expr, args: &[E
|
|||
};
|
||||
|
||||
// Require second argument to be a `Subscript`.
|
||||
if !matches!(&args[1], Expr::Subscript(_)) {
|
||||
if !args[1].is_subscript_expr() {
|
||||
return;
|
||||
}
|
||||
let Some(second_arg_info) = match_slice_info(&args[1]) else {
|
||||
|
|
|
@ -1353,7 +1353,7 @@ impl<'a> SimpleCallArgs<'a> {
|
|||
) -> Self {
|
||||
let args = args
|
||||
.into_iter()
|
||||
.take_while(|arg| !matches!(arg, Expr::Starred(_)))
|
||||
.take_while(|arg| !arg.is_starred_expr())
|
||||
.collect();
|
||||
|
||||
let kwargs = keywords
|
||||
|
@ -1404,7 +1404,7 @@ pub fn on_conditional_branch<'a>(parents: &mut impl Iterator<Item = &'a Stmt>) -
|
|||
range: _range,
|
||||
}) = parent
|
||||
{
|
||||
if matches!(value.as_ref(), Expr::IfExp(_)) {
|
||||
if value.is_if_exp_expr() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1427,7 +1427,7 @@ pub fn is_unpacking_assignment(parent: &Stmt, child: &Expr) -> bool {
|
|||
match parent {
|
||||
Stmt::With(ast::StmtWith { items, .. }) => items.iter().any(|item| {
|
||||
if let Some(optional_vars) = &item.optional_vars {
|
||||
if matches!(optional_vars.as_ref(), Expr::Tuple(_)) {
|
||||
if optional_vars.is_tuple_expr() {
|
||||
if any_over_expr(optional_vars, &|expr| expr == child) {
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue