diff --git a/src/pulp/pulp.py b/src/pulp/pulp.py index 6c6a842..898a36e 100644 --- a/src/pulp/pulp.py +++ b/src/pulp/pulp.py @@ -1311,7 +1311,7 @@ class LpProblem(object): elif isinstance(other, LpAffineExpression): self.objective = other self.objective.name = name - elif isinstance(other, LpVariable) or type(other) in [int, float]: + elif isinstance(other, LpVariable) or isinstance(other, (int, float)): self.objective = LpAffineExpression(other) self.objective.name = name else: @@ -1957,8 +1957,8 @@ def lpDot(v1, v2): return lpSum([lpDot(e1,e2) for e1,e2 in zip(v1,v2)]) def isNumber(x): - """Returns true if x is an int of a float""" - return type(x) in [int, float] + """Returns true if x is an int or a float""" + return isinstance(x, (int, float)) def value(x): """Returns the value of the variable/expression x, or x if it is a number""" diff --git a/src/pulp/solvers.py b/src/pulp/solvers.py index 21fa612..a59ea54 100644 --- a/src/pulp/solvers.py +++ b/src/pulp/solvers.py @@ -2495,7 +2495,7 @@ class GurobiFormulation(object): elif isinstance(other, LpAffineExpression): self.objective = other self.objective.name = name - elif isinstance(other, LpVariable) or type(other) in [int, float]: + elif isinstance(other, LpVariable) or isinstance(other, (int, float)): self.objective = LpAffineExpression(other) self.objective.name = name else: