Skip to content

Commit e9cabb0

Browse files
committed
Fix operator overloads in Expr class
Replaces direct comparison operators with explicit method calls (__le__, __ge__) in Expr class to ensure correct behavior when comparing expressions. Also fixes the equality operator to use __ge__ instead of == for non-ConstExpr instances.
1 parent ada1984 commit e9cabb0

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/pyscipopt/expr.pxi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class Expr:
146146
if isinstance(other, Expr):
147147
if isinstance(other, ConstExpr):
148148
return ExprCons(self, rhs=other[CONST])
149-
return (self - other) <= 0
149+
return (self - other).__le__(0)
150150
elif isinstance(other, MatrixExpr):
151151
return other.__ge__(self)
152152
raise TypeError(f"Unsupported type {type(other)}")
@@ -156,7 +156,7 @@ class Expr:
156156
if isinstance(other, Expr):
157157
if isinstance(other, ConstExpr):
158158
return ExprCons(self, lhs=other[CONST])
159-
return (self - other) >= 0
159+
return (self - other).__ge__(0)
160160
elif isinstance(other, MatrixExpr):
161161
return self.__le__(other)
162162
raise TypeError(f"Unsupported type {type(other)}")
@@ -166,7 +166,7 @@ class Expr:
166166
if isinstance(other, Expr):
167167
if isinstance(other, ConstExpr):
168168
return ExprCons(self, lhs=other[CONST], rhs=other[CONST])
169-
return (self - other) == 0
169+
return (self - other).__ge__(0)
170170
elif isinstance(other, MatrixExpr):
171171
return other.__ge__(self)
172172
raise TypeError(f"Unsupported type {type(other)}")

0 commit comments

Comments
 (0)