Skip to content

Commit f347bb3

Browse files
committed
Accept numpy scalar types in expr annotations
Add np.number to Union type annotations for buildGenExprObj and _expr_richcmp so numpy scalar types are treated as compatible GenExpr/Expr inputs. Also reformat the _expr_richcmp signature across multiple lines for readability. No behavior changes beyond broader type compatibility with numpy scalar types.
1 parent 1450215 commit f347bb3

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/pyscipopt/expr.pxi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ cdef class Term:
143143
CONST = Term()
144144

145145
# helper function
146-
def buildGenExprObj(expr: Union[int, float, Expr, GenExpr]) -> GenExpr:
146+
def buildGenExprObj(expr: Union[int, float, np.number, Expr, GenExpr]) -> GenExpr:
147147
"""helper function to generate an object of type GenExpr"""
148148
if not _is_genexpr_compatible(expr):
149149
raise TypeError(f"unsupported type {type(expr).__name__!s}")
@@ -860,7 +860,11 @@ cdef inline bint _is_expr_compatible(object o):
860860
cdef inline bint _is_genexpr_compatible(object o):
861861
return _is_expr_compatible(o) or isinstance(o, GenExpr)
862862

863-
cdef object _expr_richcmp(self, other, int op):
863+
cdef object _expr_richcmp(
864+
self,
865+
other: Union[int, float, np.number, Expr, GenExpr],
866+
int op,
867+
):
864868
if isinstance(other, np.ndarray):
865869
return NotImplemented
866870
if not _is_genexpr_compatible(other):

0 commit comments

Comments
 (0)