Skip to content

Commit 7c24f10

Browse files
committed
[ModelicaSystem] improve definition of _prepare_inputdata()
1 parent 980ac33 commit 7c24f10

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
@@ -1130,9 +1130,11 @@ def prepare_str(str_in: str) -> dict[str, str]:
11301130
if len(key_val_list) != 2:
11311131
raise ModelicaSystemError(f"Invalid 'key=value' pair: {str_in}")
11321132

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

1135-
return inputdata
1135+
return input_data_from_str
1136+
1137+
input_data: dict[str, str] = {}
11361138

11371139
if isinstance(rawinput, str):
11381140
warnings.warn(message="The definition of values to set should use a dictionary, "
@@ -1149,20 +1151,21 @@ def prepare_str(str_in: str) -> dict[str, str]:
11491151
category=DeprecationWarning,
11501152
stacklevel=3)
11511153

1152-
inputdata: dict[str, str] = {}
11531154
for item in rawinput:
1154-
inputdata |= prepare_str(item)
1155+
input_data |= prepare_str(item)
11551156

1156-
return inputdata
1157+
return input_data
11571158

11581159
if isinstance(rawinput, dict):
11591160
for key, val in rawinput.items():
11601161
str_val = str(val)
11611162
if ' ' in key or ' ' in str_val:
11621163
raise ModelicaSystemError(f"Spaces not allowed in key/value pairs: {repr(key)} = {repr(val)}!")
1163-
inputdata[key] = str_val
1164+
input_data[key] = str_val
1165+
1166+
return input_data
11641167

1165-
return inputdata
1168+
raise ModelicaSystemError(f"Invalid type of input: {type(rawinput)}")
11661169

11671170
def _set_method_helper(
11681171
self,

0 commit comments

Comments
 (0)