Skip to content

Commit 73e4254

Browse files
authored
Merge branch 'master' into type-value
2 parents 72d8f92 + 5da9e5a commit 73e4254

File tree

1 file changed

+5
-28
lines changed

1 file changed

+5
-28
lines changed

pulp/pulp.py

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -147,29 +147,6 @@
147147
LptConstExpr: TypeAlias = Union[LptNumber, "LpAffineExpression"]
148148
LptExprConstraint: TypeAlias = Union[LptExpr, "LpConstraint"]
149149

150-
try: # allow Python 2/3 compatibility
151-
maketrans = str.maketrans
152-
except AttributeError:
153-
from string import maketrans # type: ignore[attr-defined,no-redef]
154-
155-
_DICT_TYPE = dict
156-
157-
if sys.platform not in ["cli"]:
158-
# iron python does not like an OrderedDict
159-
try:
160-
from odict import OrderedDict # type: ignore[import-not-found]
161-
162-
_DICT_TYPE = OrderedDict # type: ignore[misc]
163-
except ImportError:
164-
pass
165-
try:
166-
# python 2.7 or 3.1
167-
from collections import OrderedDict
168-
169-
_DICT_TYPE = OrderedDict # type: ignore[misc]
170-
except ImportError:
171-
pass
172-
173150
try:
174151
import ujson as json # type: ignore[import-untyped]
175152
except ImportError:
@@ -184,7 +161,7 @@ class LpElement:
184161
# To remove illegal characters from the names
185162
illegal_chars = "-+[] ->/"
186163
expression = re.compile(f"[{re.escape(illegal_chars)}]")
187-
trans = maketrans(illegal_chars, "________")
164+
trans = str.maketrans(illegal_chars, "________")
188165

189166
def setName(self, name):
190167
if name:
@@ -672,7 +649,7 @@ def unfixValue(self):
672649
self.bounds(self._lowbound_original, self._upbound_original)
673650

674651

675-
class LpAffineExpression(_DICT_TYPE):
652+
class LpAffineExpression(dict):
676653
"""
677654
A linear combination of :class:`LpVariables<LpVariable>`.
678655
Can be initialised with the following:
@@ -696,7 +673,7 @@ class LpAffineExpression(_DICT_TYPE):
696673
"""
697674

698675
# to remove illegal characters from the names
699-
trans = maketrans("-+[] ", "_____")
676+
trans = str.maketrans("-+[] ", "_____")
700677

701678
@property
702679
def name(self) -> str | None:
@@ -1430,7 +1407,7 @@ def __init__(self, name="NoName", sense=const.LpMinimize):
14301407
warnings.warn("Spaces are not permitted in the name. Converted to '_'")
14311408
name = name.replace(" ", "_")
14321409
self.objective: None | LpAffineExpression = None # type: ignore[annotation-unchecked]
1433-
self.constraints: dict[str, LpConstraint] = _DICT_TYPE() # type: ignore[annotation-unchecked]
1410+
self.constraints: dict[str, LpConstraint] = {} # type: ignore[annotation-unchecked]
14341411
self.name = name
14351412
self.sense = sense
14361413
self.sos1 = {}
@@ -1498,7 +1475,7 @@ def deepcopy(self):
14981475
lpcopy = LpProblem(name=self.name, sense=self.sense)
14991476
if self.objective is not None:
15001477
lpcopy.objective = self.objective.copy()
1501-
lpcopy.constraints = _DICT_TYPE[str, LpConstraint]()
1478+
lpcopy.constraints = {}
15021479
for k, v in self.constraints.items():
15031480
lpcopy.constraints[k] = v.copy()
15041481
lpcopy.sos1 = self.sos1.copy()

0 commit comments

Comments
 (0)