[red-knot] binary arithmetic on instances (#13800)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Carl Meyer 2024-10-19 08:22:54 -07:00 committed by GitHub
parent 36cb1199cc
commit f4b5e70fae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 656 additions and 41 deletions

View file

@ -2971,6 +2971,42 @@ impl Operator {
Operator::FloorDiv => "//",
}
}
pub const fn dunder(self) -> &'static str {
match self {
Operator::Add => "__add__",
Operator::Sub => "__sub__",
Operator::Mult => "__mul__",
Operator::MatMult => "__matmul__",
Operator::Div => "__truediv__",
Operator::Mod => "__mod__",
Operator::Pow => "__pow__",
Operator::LShift => "__lshift__",
Operator::RShift => "__rshift__",
Operator::BitOr => "__or__",
Operator::BitXor => "__xor__",
Operator::BitAnd => "__and__",
Operator::FloorDiv => "__floordiv__",
}
}
pub const fn reflected_dunder(self) -> &'static str {
match self {
Operator::Add => "__radd__",
Operator::Sub => "__rsub__",
Operator::Mult => "__rmul__",
Operator::MatMult => "__rmatmul__",
Operator::Div => "__rtruediv__",
Operator::Mod => "__rmod__",
Operator::Pow => "__rpow__",
Operator::LShift => "__rlshift__",
Operator::RShift => "__rrshift__",
Operator::BitOr => "__ror__",
Operator::BitXor => "__rxor__",
Operator::BitAnd => "__rand__",
Operator::FloorDiv => "__rfloordiv__",
}
}
}
impl fmt::Display for Operator {