Skip to content

Commit

Permalink
pr review: avoid superfluous into_class_literal
Browse files Browse the repository at this point in the history
  • Loading branch information
connorskees committed Dec 3, 2024
1 parent fcfc535 commit d8d4585
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions crates/red_knot_python_semantic/src/types/narrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,23 +426,17 @@ impl<'db> NarrowingConstraintsBuilder<'db> {
},
)
}
Type::ClassLiteral(..) => {
let is_valid_bool_invocation =
expr_call.arguments.args.len() == 1 && expr_call.arguments.keywords.is_empty();

if is_valid_bool_invocation
&& callable_ty
.into_class_literal()
.is_some_and(|lit| lit.class.is_known(self.db, KnownClass::Bool))
{
self.evaluate_expression_node_constraint(
&expr_call.arguments.args[0],
expression,
is_positive,
)
} else {
None
}
// for the expression `bool(E)`, we further narrow the type based on `E`
Type::ClassLiteral(class_type)
if expr_call.arguments.args.len() == 1
&& expr_call.arguments.keywords.is_empty()
&& class_type.class.is_known(self.db, KnownClass::Bool) =>
{
self.evaluate_expression_node_constraint(
&expr_call.arguments.args[0],
expression,
is_positive,
)
}
_ => None,
}
Expand Down

0 comments on commit d8d4585

Please sign in to comment.