mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-09 18:02:19 +00:00
[red-knot] Narrowing - Not operator (#13942)
## Summary After #13918 has landed, narrowing constraint negation became easy, so adding support for `not` operator. ## Test Plan Added a new mdtest file for `not` expression. --------- Co-authored-by: Carl Meyer <carl@astral.sh>
This commit is contained in:
parent
1f19aca632
commit
74cf66e4c2
2 changed files with 51 additions and 1 deletions
|
@ -129,13 +129,30 @@ impl<'db> NarrowingConstraintsBuilder<'db> {
|
|||
}
|
||||
|
||||
fn evaluate_expression_constraint(&mut self, expression: Expression<'db>, is_positive: bool) {
|
||||
match expression.node_ref(self.db).node() {
|
||||
let expression_node = expression.node_ref(self.db).node();
|
||||
self.evaluate_expression_node_constraint(expression_node, expression, is_positive);
|
||||
}
|
||||
|
||||
fn evaluate_expression_node_constraint(
|
||||
&mut self,
|
||||
expression_node: &ruff_python_ast::Expr,
|
||||
expression: Expression<'db>,
|
||||
is_positive: bool,
|
||||
) {
|
||||
match expression_node {
|
||||
ast::Expr::Compare(expr_compare) => {
|
||||
self.add_expr_compare(expr_compare, expression, is_positive);
|
||||
}
|
||||
ast::Expr::Call(expr_call) => {
|
||||
self.add_expr_call(expr_call, expression, is_positive);
|
||||
}
|
||||
ast::Expr::UnaryOp(unary_op) if unary_op.op == ast::UnaryOp::Not => {
|
||||
self.evaluate_expression_node_constraint(
|
||||
&unary_op.operand,
|
||||
expression,
|
||||
!is_positive,
|
||||
);
|
||||
}
|
||||
_ => {} // TODO other test expression kinds
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue