Skip to content

Commit 111326f

Browse files
committed
[ModelicaSystem._xmlparse] mypy fixes & cleanup
1 parent 4ed4bc9 commit 111326f

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

OMPython/ModelicaSystem.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,21 +520,32 @@ def _xmlparse(self, xml_file: pathlib.Path):
520520
for attr in rootCQ.iter('DefaultExperiment'):
521521
for key in ("startTime", "stopTime", "stepSize", "tolerance",
522522
"solver", "outputFormat"):
523-
self._simulate_options[key] = attr.get(key)
523+
self._simulate_options[key] = str(attr.get(key))
524524

525525
for sv in rootCQ.iter('ScalarVariable'):
526-
scalar = {}
527-
for key in ("name", "description", "variability", "causality", "alias"):
528-
scalar[key] = sv.get(key)
529-
scalar["changeable"] = sv.get('isValueChangeable')
530-
scalar["aliasvariable"] = sv.get('aliasVariable')
526+
translations = {
527+
"alias": "alias",
528+
"aliasvariable": "aliasVariable",
529+
"causality": "causality",
530+
"changeable": "isValueChangeable",
531+
"description": "description",
532+
"name": "name",
533+
"variability": "variability",
534+
}
535+
536+
scalar: dict[str, Any] = {}
537+
for key_dst, key_src in translations.items():
538+
val = sv.get(key_src)
539+
scalar[key_dst] = None if val is None else str(val)
540+
531541
ch = list(sv)
532542
for att in ch:
533543
scalar["start"] = att.get('start')
534544
scalar["min"] = att.get('min')
535545
scalar["max"] = att.get('max')
536546
scalar["unit"] = att.get('unit')
537547

548+
# save parameters in the corresponding class variables
538549
if scalar["variability"] == "parameter":
539550
if scalar["name"] in self._override_variables:
540551
self._params[scalar["name"]] = self._override_variables[scalar["name"]]

0 commit comments

Comments
 (0)