Skip to content

Commit 8a6ac41

Browse files
authored
Fix for TypeError: can only concatenate str (not "type") to str (#288)
* Fixed type error (cannot concatenate string and type) * Added unit test (not testing variable removal atm)
1 parent 08b3ad4 commit 8a6ac41

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

mip/model.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,8 +1427,7 @@ def remove(
14271427
else:
14281428
raise TypeError(
14291429
"Cannot handle removal of object of type "
1430-
+ type(objects)
1431-
+ " from model."
1430+
"{} from model".format(type(objects))
14321431
)
14331432

14341433
def translate(self: "Model", ref) -> Union[List[Any], Dict[Any, Any], "mip.Var"]:

test/test_model.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import re
23

34
import pytest
45

@@ -1260,3 +1261,20 @@ def test_query_attributes_of_lin_expr(solver):
12601261
assert constr_expr.violation is None
12611262

12621263
m.optimize()
1264+
1265+
1266+
@pytest.mark.parametrize("solver", SOLVERS)
1267+
def test_remove(solver):
1268+
m = Model(solver_name=solver)
1269+
x = m.add_var("x")
1270+
constr = m.add_constr(x >= 0)
1271+
m.objective = x
1272+
1273+
with pytest.raises(TypeError, match=re.escape("Cannot handle removal of object of type <class 'NoneType'> from model")):
1274+
m.remove(None)
1275+
1276+
with pytest.raises(TypeError, match=re.escape("Cannot handle removal of object of type <class 'NoneType'> from model")):
1277+
m.remove([None])
1278+
1279+
m.remove(constr)
1280+
# TODO: Test the removal of variables (currently failing, see https://github.com/coin-or/python-mip/pull/288#discussion_r919215654)

0 commit comments

Comments
 (0)