From 25c3be51d24e4436654baabe8f4ae79dfc31fa02 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Thu, 24 Apr 2025 08:11:45 -0700 Subject: [PATCH] [red-knot] simplify != narrowing (#17610) ## Summary Follow-up from review comment in https://github.com/astral-sh/ruff/pull/17567#discussion_r2058649527 ## Test Plan Existing tests. --- .../src/types/narrow.rs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/crates/red_knot_python_semantic/src/types/narrow.rs b/crates/red_knot_python_semantic/src/types/narrow.rs index 1dfac5b041..3c49626461 100644 --- a/crates/red_knot_python_semantic/src/types/narrow.rs +++ b/crates/red_knot_python_semantic/src/types/narrow.rs @@ -512,19 +512,10 @@ impl<'db> NarrowingConstraintsBuilder<'db> { None } } - (_, Type::BooleanLiteral(b)) => { - if b { - Some( - UnionType::from_elements(self.db, [rhs_ty, Type::IntLiteral(1)]) - .negate(self.db), - ) - } else { - Some( - UnionType::from_elements(self.db, [rhs_ty, Type::IntLiteral(0)]) - .negate(self.db), - ) - } - } + (_, Type::BooleanLiteral(b)) => Some( + UnionType::from_elements(self.db, [rhs_ty, Type::IntLiteral(i64::from(b))]) + .negate(self.db), + ), _ if rhs_ty.is_single_valued(self.db) => Some(rhs_ty.negate(self.db)), _ => None, }