[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.
This commit is contained in:
Carl Meyer 2025-04-24 08:11:45 -07:00 committed by GitHub
parent e71f3ed2c5
commit 25c3be51d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 13 deletions

View File

@ -512,19 +512,10 @@ impl<'db> NarrowingConstraintsBuilder<'db> {
None None
} }
} }
(_, Type::BooleanLiteral(b)) => { (_, Type::BooleanLiteral(b)) => Some(
if b { UnionType::from_elements(self.db, [rhs_ty, Type::IntLiteral(i64::from(b))])
Some( .negate(self.db),
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),
)
}
}
_ if rhs_ty.is_single_valued(self.db) => Some(rhs_ty.negate(self.db)), _ if rhs_ty.is_single_valued(self.db) => Some(rhs_ty.negate(self.db)),
_ => None, _ => None,
} }