@@ -484,6 +484,14 @@ def print(self, display_max_rows: int = 20, display_max_terms: int = 20) -> None
484484 )
485485 print (self )
486486
487+ @overload
488+ def __add__ (
489+ self , other : ConstantLike | Variable | ScalarLinearExpression | LinearExpression
490+ ) -> LinearExpression : ...
491+
492+ @overload
493+ def __add__ (self , other : QuadraticExpression ) -> QuadraticExpression : ...
494+
487495 def __add__ (self , other : SideLike ) -> LinearExpression | QuadraticExpression :
488496 """
489497 Add an expression to others.
@@ -506,24 +514,16 @@ def __add__(self, other: SideLike) -> LinearExpression | QuadraticExpression:
506514 def __radd__ (self , other : ConstantLike ) -> LinearExpression :
507515 return self .__add__ (other )
508516
509- def __sub__ (self , other : SideLike ) -> LinearExpression :
510- """
511- Subtract others from expression.
512-
513- Note: If other is a numpy array or pandas object without axes names,
514- dimension names of self will be filled in other
515- """
516- if isinstance (other , QuadraticExpression ):
517- return other .__rsub__ (self )
517+ @overload
518+ def __sub__ (
519+ self , other : ConstantLike | Variable | ScalarLinearExpression | LinearExpression
520+ ) -> LinearExpression : ...
518521
519- try :
520- if np .isscalar (other ):
521- return self .assign_multiindex_safe (const = self .const - other )
522+ @overload
523+ def __sub__ (self , other : QuadraticExpression ) -> QuadraticExpression : ...
522524
523- other = as_expression (other , model = self .model , dims = self .coord_dims )
524- return merge ([self , - other ], cls = self .__class__ )
525- except TypeError :
526- return NotImplemented
525+ def __sub__ (self , other : SideLike ) -> LinearExpression | QuadraticExpression :
526+ return self .__add__ (- other )
527527
528528 def __neg__ (self ) -> LinearExpression :
529529 """
0 commit comments