Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
InSyncWithFoo committed Nov 22, 2024
1 parent b370578 commit 7ca3981
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ pub(crate) fn function_call_in_dataclass_default(
DataclassKind::Attrs(attrs_auto_attribs) => match attrs_auto_attribs {
AttrsAutoAttribs::Unknown => return,

AttrsAutoAttribs::None => match any_annotated(&class_def.body) {
true => Some(AttrsAutoAttribs::True),
false => Some(AttrsAutoAttribs::False),
},
AttrsAutoAttribs::None => {
if any_annotated(&class_def.body) {
Some(AttrsAutoAttribs::True)
} else {
Some(AttrsAutoAttribs::False)
}
}

_ => Some(attrs_auto_attribs),
},
Expand Down Expand Up @@ -151,7 +154,7 @@ pub(crate) fn function_call_in_dataclass_default(
}

#[inline]
fn any_annotated(class_body: &Vec<Stmt>) -> bool {
fn any_annotated(class_body: &[Stmt]) -> bool {
class_body
.iter()
.any(|stmt| matches!(stmt, Stmt::AnnAssign(..)))
Expand Down
18 changes: 11 additions & 7 deletions crates/ruff_linter/src/rules/ruff/rules/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ pub(super) fn dataclass_kind(
// https://www.attrs.org/en/stable/api.html#attrs.define
// https://www.attrs.org/en/stable/api-attr.html#attr.s
let Expr::Call(ExprCall { arguments, .. }) = &decorator.expression else {
let auto_attribs = match func.as_ref() {
"s" => AttrsAutoAttribs::False,
_ => AttrsAutoAttribs::None,
let auto_attribs = if *func == "s" {
AttrsAutoAttribs::False
} else {
AttrsAutoAttribs::None
};

return Some(DataclassKind::Attrs(auto_attribs));
Expand All @@ -148,10 +149,13 @@ pub(super) fn dataclass_kind(
};

let auto_attribs = match &auto_attribs.value {
Expr::BooleanLiteral(literal) => match literal.value {
true => AttrsAutoAttribs::True,
false => AttrsAutoAttribs::False,
},
Expr::BooleanLiteral(literal) => {
if literal.value {
AttrsAutoAttribs::True
} else {
AttrsAutoAttribs::False
}
}
Expr::NoneLiteral(..) => AttrsAutoAttribs::None,
_ => AttrsAutoAttribs::Unknown,
};
Expand Down

0 comments on commit 7ca3981

Please sign in to comment.