Skip to content

Commit 2a69af4

Browse files
committed
fixed python3.13 processing structures in side mip/lists.py and mip/model.py
1 parent 9607cb2 commit 2a69af4

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

mip/lists.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def add(
4949
return new_var
5050

5151
def __getitem__(self: "VarList", key):
52+
if key is None:
53+
raise KeyError("Empty key access (e.g., varlist[]) is not allowed in Python 3.13")
5254
if isinstance(key, str):
5355
return self.__model.var_by_name(key)
5456
return self.__vars[key]

mip/model.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ def __init__(
5353
solver: Optional[mip.Solver] = None,
5454
):
5555
"""Model constructor
56+
tests/unit/test_portfolio_optimisation/hs/execution/reports/test_aantal_ibn_report.py:29 (TestCaseAantalIBNReport.test_aantal_ibn_vraag_overview)
57+
2 != 3
58+
59+
Expected :3
60+
Actual :2
61+
<Click to see difference>
62+
63+
cls = <class 'tests.unit.test_portfolio_optimisation.hs.execution.reports.test_aantal_ibn_report.TestCaseAantalIBNReport'>
64+
65+
@classmethod
66+
def setUp(cls):
67+
cls.portfolio = dummy_hs_portfolio()
68+
> model, result = optimize_plan(cls.portfolio)
69+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
70+
71+
tests/unit/test_portfolio_optimisation/hs/execution/reports/test_aantal_ibn_report.py:27: AssertionError
72+
5673
5774
Creates a Mixed-Integer Linear Programming Model. The default model
5875
optimization direction is Minimization. To store and optimize the model
@@ -471,7 +488,7 @@ def constr_by_name(self: "Model", name: str) -> Optional["mip.Constr"]:
471488
constraint or None if not found
472489
"""
473490
cidx = self.solver.constr_get_index(name)
474-
if cidx < 0 or cidx > len(self.constrs):
491+
if cidx < 0 or cidx >= len(self.constrs):
475492
return None
476493
return self.constrs[cidx]
477494

@@ -484,7 +501,7 @@ def var_by_name(self: "Model", name: str) -> Optional["mip.Var"]:
484501
Variable or None if not found
485502
"""
486503
v = self.solver.var_get_index(name)
487-
if v < 0 or v > len(self.vars):
504+
if v < 0 or v >= len(self.vars):
488505
return None
489506
return self.vars[v]
490507

0 commit comments

Comments
 (0)