Skip to content

Commit 5707e20

Browse files
committed
Refine type hints: use np alias and add overloads
Improve typing in src/pyscipopt/scip.pyi: import Union and overload, alias numpy as np, and switch class bases from numpy.ndarray to np.ndarray. Add overloads for Model.getSolVal and Model.getVal to distinguish scalar returns (Expr/GenExpr -> float) from matrix returns (MatrixExpr -> np.ndarray), improving type accuracy for consumers and IDE/type-checkers.
1 parent a220ae4 commit 5707e20

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

src/pyscipopt/scip.pyi

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from typing import ClassVar
1+
from typing import ClassVar, Union, overload
22

3-
import numpy
3+
import numpy as np
44
from _typeshed import Incomplete
55
from typing_extensions import disjoint_base
66

@@ -496,7 +496,7 @@ class LP:
496496
def solve(self, dual: Incomplete = ...) -> Incomplete: ...
497497
def writeLP(self, filename: Incomplete) -> Incomplete: ...
498498

499-
class MatrixConstraint(numpy.ndarray):
499+
class MatrixConstraint(np.ndarray):
500500
def getConshdlrName(self) -> Incomplete: ...
501501
def isActive(self) -> Incomplete: ...
502502
def isChecked(self) -> Incomplete: ...
@@ -512,7 +512,7 @@ class MatrixConstraint(numpy.ndarray):
512512
def isSeparated(self) -> Incomplete: ...
513513
def isStickingAtNode(self) -> Incomplete: ...
514514

515-
class MatrixExpr(numpy.ndarray):
515+
class MatrixExpr(np.ndarray):
516516
def _evaluate(self, sol: Incomplete) -> Incomplete: ...
517517
def __array_ufunc__(
518518
self,
@@ -522,7 +522,7 @@ class MatrixExpr(numpy.ndarray):
522522
**kwargs: Incomplete,
523523
) -> Incomplete: ...
524524

525-
class MatrixExprCons(numpy.ndarray):
525+
class MatrixExprCons(np.ndarray):
526526
def __array_ufunc__(
527527
self,
528528
ufunc: Incomplete,
@@ -1215,7 +1215,10 @@ class Model:
12151215
self, sol: Incomplete, original: Incomplete = ...
12161216
) -> Incomplete: ...
12171217
def getSolTime(self, sol: Incomplete) -> Incomplete: ...
1218-
def getSolVal(self, sol: Incomplete, expr: Incomplete) -> Incomplete: ...
1218+
@overload
1219+
def getSolVal(self, sol: Solution, expr: Union[Expr, GenExpr]) -> float: ...
1220+
@overload
1221+
def getSolVal(self, sol: Solution, expr: MatrixExpr) -> np.ndarray: ...
12191222
def getSols(self) -> Incomplete: ...
12201223
def getSolvingTime(self) -> Incomplete: ...
12211224
def getStage(self) -> Incomplete: ...
@@ -1227,7 +1230,10 @@ class Model:
12271230
def getTransformedCons(self, cons: Incomplete) -> Incomplete: ...
12281231
def getTransformedVar(self, var: Incomplete) -> Incomplete: ...
12291232
def getTreesizeEstimation(self) -> Incomplete: ...
1230-
def getVal(self, expr: Incomplete) -> Incomplete: ...
1233+
@overload
1234+
def getVal(self, expr: Union[Expr, GenExpr]) -> float: ...
1235+
@overload
1236+
def getVal(self, expr: MatrixExpr) -> np.ndarray: ...
12311237
def getValsLinear(self, cons: Incomplete) -> Incomplete: ...
12321238
def getVarDict(self, transformed: Incomplete = ...) -> Incomplete: ...
12331239
def getVarLbDive(self, var: Incomplete) -> Incomplete: ...

0 commit comments

Comments
 (0)