Skip to content

Commit 7f89c06

Browse files
committed
fix mypy issues maybe
1 parent 8eb9fdc commit 7f89c06

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

doc/release_notes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Release Notes
33

44
.. Upcoming Version
55
6-
* Allow constant values in objective cost function
6+
* Allow constant values in objective cost function. Refactored objective setting.
77
* Add support for SOS1 and SOS2 (Special Ordered Sets) constraints via ``Model.add_sos_constraints()`` and ``Model.remove_sos_constraints()``
88
* Add simplify method to LinearExpression to combine duplicate terms
99
* Add convenience function to create LinearExpression from constant

linopy/model.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def objective(self) -> Objective:
266266

267267
@objective.setter
268268
def objective(
269-
self, obj: Objective | LinearExpression | QuadraticExpression
269+
self, obj: Objective | Variable | LinearExpression | QuadraticExpression
270270
) -> Objective:
271271
self.add_objective(expr=obj, overwrite=True, allow_constant=False)
272272
return self._objective
@@ -779,7 +779,7 @@ def add_constraints(
779779
return constraint
780780

781781
@overload
782-
def add_objective(
782+
def add_objective( # Set objective as Objective object
783783
self,
784784
expr: Objective,
785785
sense: None = None,
@@ -788,7 +788,7 @@ def add_objective(
788788
) -> None: ...
789789

790790
@overload
791-
def add_objective(
791+
def add_objective( # Set objective as expression-like with sense
792792
self,
793793
expr: Variable
794794
| LinearExpression
@@ -834,6 +834,9 @@ def add_objective(
834834
" Set `overwrite` to True to force overwriting."
835835
)
836836

837+
if isinstance(expr, list | tuple):
838+
expr: LinearExpression = self.linexpr(*expr)
839+
837840
if isinstance(expr, Objective):
838841
assert sense is None, "Cannot set sense if objective object is passed"
839842
objective = expr

linopy/objective.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,14 @@ def model(self) -> Model:
213213
return self._model
214214

215215
@property
216-
def sense(self) -> str:
216+
def sense(self) -> Literal["min", "max"]:
217217
"""
218218
Returns the sense of the objective.
219219
"""
220220
return self._sense
221221

222222
@sense.setter
223-
def sense(self, sense: str) -> None:
223+
def sense(self, sense: Literal["min", "max"]) -> None:
224224
"""
225225
Sets the sense of the objective.
226226
"""

0 commit comments

Comments
 (0)