Skip to content

Commit 25c3be5

Browse files
authored
[red-knot] simplify != narrowing (#17610)
## Summary Follow-up from review comment in #17567 (comment) ## Test Plan Existing tests.
1 parent e71f3ed commit 25c3be5

File tree

1 file changed

+4
-13
lines changed
  • crates/red_knot_python_semantic/src/types

1 file changed

+4
-13
lines changed

crates/red_knot_python_semantic/src/types/narrow.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -512,19 +512,10 @@ impl<'db> NarrowingConstraintsBuilder<'db> {
512512
None
513513
}
514514
}
515-
(_, Type::BooleanLiteral(b)) => {
516-
if b {
517-
Some(
518-
UnionType::from_elements(self.db, [rhs_ty, Type::IntLiteral(1)])
519-
.negate(self.db),
520-
)
521-
} else {
522-
Some(
523-
UnionType::from_elements(self.db, [rhs_ty, Type::IntLiteral(0)])
524-
.negate(self.db),
525-
)
526-
}
527-
}
515+
(_, Type::BooleanLiteral(b)) => Some(
516+
UnionType::from_elements(self.db, [rhs_ty, Type::IntLiteral(i64::from(b))])
517+
.negate(self.db),
518+
),
528519
_ if rhs_ty.is_single_valued(self.db) => Some(rhs_ty.negate(self.db)),
529520
_ => None,
530521
}

0 commit comments

Comments
 (0)