Skip to content

Commit 337803b

Browse files
committed
Handle Number type in UnaryExpr constructor
Updated UnaryExpr to accept Number types directly and convert them to ConstExpr instances. This improves type handling and consistency when constructing unary expressions.
1 parent bd00b91 commit 337803b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/pyscipopt/expr.pxi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,9 @@ class PowExpr(FuncExpr):
428428
class UnaryExpr(FuncExpr):
429429
"""Expression like `f(expression)`."""
430430

431-
def __init__(self, expr: Union[int, float, Variable, Term, Expr]):
431+
def __init__(self, expr: Union[Number, Variable, Term, Expr]):
432+
if isinstance(expr, Number):
433+
expr = ConstExpr(expr)
432434
super().__init__({expr: 1.0})
433435

434436
def __hash__(self):

0 commit comments

Comments
 (0)