mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:44:56 +00:00
[ty] fix binary expression inference between boolean literals and bool
instances (#18663)
This commit is contained in:
parent
87f0feb21a
commit
932f941d15
2 changed files with 80 additions and 16 deletions
|
@ -6893,22 +6893,22 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
|||
(Type::BooleanLiteral(b1), Type::BooleanLiteral(b2), ast::Operator::BitXor) => {
|
||||
Some(Type::BooleanLiteral(b1 ^ b2))
|
||||
}
|
||||
|
||||
(Type::BooleanLiteral(bool_value), right, op) => self.infer_binary_expression_type(
|
||||
node,
|
||||
emitted_division_by_zero_diagnostic,
|
||||
Type::IntLiteral(i64::from(bool_value)),
|
||||
right,
|
||||
op,
|
||||
),
|
||||
(left, Type::BooleanLiteral(bool_value), op) => self.infer_binary_expression_type(
|
||||
node,
|
||||
emitted_division_by_zero_diagnostic,
|
||||
left,
|
||||
Type::IntLiteral(i64::from(bool_value)),
|
||||
op,
|
||||
),
|
||||
|
||||
(Type::BooleanLiteral(b1), Type::BooleanLiteral(_) | Type::IntLiteral(_), op) => self
|
||||
.infer_binary_expression_type(
|
||||
node,
|
||||
emitted_division_by_zero_diagnostic,
|
||||
Type::IntLiteral(i64::from(b1)),
|
||||
right_ty,
|
||||
op,
|
||||
),
|
||||
(Type::IntLiteral(_), Type::BooleanLiteral(b2), op) => self
|
||||
.infer_binary_expression_type(
|
||||
node,
|
||||
emitted_division_by_zero_diagnostic,
|
||||
left_ty,
|
||||
Type::IntLiteral(i64::from(b2)),
|
||||
op,
|
||||
),
|
||||
(Type::Tuple(lhs), Type::Tuple(rhs), ast::Operator::Add) => {
|
||||
// Note: this only works on heterogeneous tuples.
|
||||
let lhs_elements = lhs.elements(self.db());
|
||||
|
@ -6927,6 +6927,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
|||
// fall back on looking for dunder methods on one of the operand types.
|
||||
(
|
||||
Type::FunctionLiteral(_)
|
||||
| Type::BooleanLiteral(_)
|
||||
| Type::Callable(..)
|
||||
| Type::BoundMethod(_)
|
||||
| Type::WrapperDescriptor(_)
|
||||
|
@ -6954,6 +6955,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
|||
| Type::TypeVar(_)
|
||||
| Type::TypeIs(_),
|
||||
Type::FunctionLiteral(_)
|
||||
| Type::BooleanLiteral(_)
|
||||
| Type::Callable(..)
|
||||
| Type::BoundMethod(_)
|
||||
| Type::WrapperDescriptor(_)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue