mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:09:22 +00:00
[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:
parent
3006d6da23
commit
35f007f17f
17 changed files with 363 additions and 53 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue