[red-knot] Type narrow in else clause (#13918)

## Summary

Add support for type narrowing in elif and else scopes as part of
#13694.

## Test Plan

- mdtest
- builder unit test for union negation.

---------

Co-authored-by: Carl Meyer <carl@astral.sh>
This commit is contained in:
TomerBin 2024-10-26 19:22:57 +03:00 committed by GitHub
parent 3006d6da23
commit 35f007f17f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 363 additions and 53 deletions

View file

@ -3071,6 +3071,22 @@ impl CmpOp {
CmpOp::NotIn => "not in",
}
}
#[must_use]
pub const fn negate(&self) -> Self {
match self {
CmpOp::Eq => CmpOp::NotEq,
CmpOp::NotEq => CmpOp::Eq,
CmpOp::Lt => CmpOp::GtE,
CmpOp::LtE => CmpOp::Gt,
CmpOp::Gt => CmpOp::LtE,
CmpOp::GtE => CmpOp::Lt,
CmpOp::Is => CmpOp::IsNot,
CmpOp::IsNot => CmpOp::Is,
CmpOp::In => CmpOp::NotIn,
CmpOp::NotIn => CmpOp::In,
}
}
}
impl fmt::Display for CmpOp {