Skip to content

Commit

Permalink
Fix clippy suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp committed Jan 7, 2025
1 parent 2e2649a commit 855d6db
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
5 changes: 4 additions & 1 deletion crates/red_knot_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,10 @@ impl<'db> Type<'db> {
if truthiness.is_always_true() {
CallOutcome::callable(binding)
} else {
CallOutcome::StaticAssertionError { ty, truthiness }
CallOutcome::StaticAssertionError {
argument_ty: ty,
truthiness,
}
}
}

Expand Down
27 changes: 17 additions & 10 deletions crates/red_knot_python_semantic/src/types/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(super) enum CallOutcome<'db> {
call_outcome: Box<CallOutcome<'db>>,
},
StaticAssertionError {
ty: Type<'db>,
argument_ty: Type<'db>,
truthiness: Truthiness,
},
}
Expand Down Expand Up @@ -260,7 +260,7 @@ impl<'db> CallOutcome<'db> {
}
}
CallOutcome::StaticAssertionError {
ty: Type::BooleanLiteral(false),
argument_ty: Type::BooleanLiteral(false),
truthiness: _,
} => {
context.report_lint(
Expand All @@ -271,31 +271,38 @@ impl<'db> CallOutcome<'db> {

Ok(Type::Unknown)
}
CallOutcome::StaticAssertionError { ty, truthiness }
if truthiness.is_always_false() =>
{
CallOutcome::StaticAssertionError {
argument_ty,
truthiness,
} if truthiness.is_always_false() => {
context.report_lint(
&STATIC_ASSERT_ERROR,
node,
format_args!("Static assertion error: argument of type `{ty}` is statically known to be falsy", ty=ty.display(db)),
format_args!("Static assertion error: argument of type `{argument_ty}` is statically known to be falsy", argument_ty=argument_ty.display(db)),
);

Ok(Type::Unknown)
}
CallOutcome::StaticAssertionError { ty, truthiness } if truthiness.is_ambiguous() => {
CallOutcome::StaticAssertionError {
argument_ty,
truthiness,
} if truthiness.is_ambiguous() => {
context.report_lint(
&STATIC_ASSERT_ERROR,
node,
format_args!("Static assertion error: argument of type `{ty}` has an ambiguous static truthiness", ty=ty.display(db)),
format_args!("Static assertion error: argument of type `{argument_ty}` has an ambiguous static truthiness", argument_ty=argument_ty.display(db)),
);

Ok(Type::Unknown)
}
CallOutcome::StaticAssertionError { ty, truthiness: _ } => {
CallOutcome::StaticAssertionError {
argument_ty,
truthiness: _,
} => {
context.report_lint(
&STATIC_ASSERT_ERROR,
node,
format_args!("Static assertion error: expected argument of type `{ty}` to have static truthiness", ty=ty.display(db)),
format_args!("Static assertion error: expected argument of type `{argument_ty}` to have static truthiness", argument_ty=argument_ty.display(db)),
);

Ok(Type::Unknown)
Expand Down
2 changes: 1 addition & 1 deletion crates/red_knot_python_semantic/src/types/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3052,7 +3052,7 @@ impl<'db> TypeInferenceBuilder<'db> {
let infer_arguments_as_type_expressions = function_type
.into_function_literal()
.and_then(|f| f.known(self.db()))
.is_some_and(|f| f.takes_type_expression_arguments());
.is_some_and(KnownFunction::takes_type_expression_arguments);

let call_arguments = self.infer_arguments(arguments, infer_arguments_as_type_expressions);
function_type
Expand Down

0 comments on commit 855d6db

Please sign in to comment.