Skip to content

Commit 3133f61

Browse files
committed
[ModelicaSystem._xmlparse] mypy fixes & cleanup
1 parent c4fabc5 commit 3133f61

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

OMPython/ModelicaSystem.py

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

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

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

0 commit comments

Comments
 (0)