Skip to content

Commit 0301043

Browse files
committed
[ModelicaSystem] improve definition of _prepare_inputdata()
1 parent bf3a1a4 commit 0301043

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,9 +1005,11 @@ def prepare_str(str_in: str) -> dict[str, str]:
10051005
if len(key_val_list) != 2:
10061006
raise ModelicaSystemError(f"Invalid 'key=value' pair: {str_in}")
10071007

1008-
inputdata = {key_val_list[0]: key_val_list[1]}
1008+
input_data_from_str: dict[str, str] = {key_val_list[0]: key_val_list[1]}
10091009

1010-
return inputdata
1010+
return input_data_from_str
1011+
1012+
input_data: dict[str, str] = {}
10111013

10121014
if isinstance(rawinput, str):
10131015
warnings.warn(message="The definition of values to set should use a dictionary, "
@@ -1024,20 +1026,21 @@ def prepare_str(str_in: str) -> dict[str, str]:
10241026
category=DeprecationWarning,
10251027
stacklevel=3)
10261028

1027-
inputdata: dict[str, str] = {}
10281029
for item in rawinput:
1029-
inputdata |= prepare_str(item)
1030+
input_data |= prepare_str(item)
10301031

1031-
return inputdata
1032+
return input_data
10321033

10331034
if isinstance(rawinput, dict):
10341035
for key, val in rawinput.items():
10351036
str_val = str(val)
10361037
if ' ' in key or ' ' in str_val:
10371038
raise ModelicaSystemError(f"Spaces not allowed in key/value pairs: {repr(key)} = {repr(val)}!")
1038-
inputdata[key] = str_val
1039+
input_data[key] = str_val
1040+
1041+
return input_data
10391042

1040-
return inputdata
1043+
raise ModelicaSystemError(f"Invalid type of input: {type(rawinput)}")
10411044

10421045
def _set_method_helper(
10431046
self,

0 commit comments

Comments
 (0)