Skip to content

Commit ee2ee10

Browse files
committed
[ModelicaSystem] improve definition of _prepare_inputdata()
1 parent f40957f commit ee2ee10

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

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

1090-
return inputdata
1090+
return input_data_from_str
1091+
1092+
input_data: dict[str, str] = {}
10911093

10921094
if isinstance(rawinput, str):
10931095
warnings.warn(message="The definition of values to set should use a dictionary, "
@@ -1104,20 +1106,21 @@ def prepare_str(str_in: str) -> dict[str, str]:
11041106
category=DeprecationWarning,
11051107
stacklevel=3)
11061108

1107-
inputdata: dict[str, str] = {}
11081109
for item in rawinput:
1109-
inputdata |= prepare_str(item)
1110+
input_data |= prepare_str(item)
11101111

1111-
return inputdata
1112+
return input_data
11121113

11131114
if isinstance(rawinput, dict):
11141115
for key, val in rawinput.items():
11151116
str_val = str(val)
11161117
if ' ' in key or ' ' in str_val:
11171118
raise ModelicaSystemError(f"Spaces not allowed in key/value pairs: {repr(key)} = {repr(val)}!")
1118-
inputdata[key] = str_val
1119+
input_data[key] = str_val
1120+
1121+
return input_data
11191122

1120-
return inputdata
1123+
raise ModelicaSystemError(f"Invalid type of input: {type(rawinput)}")
11211124

11221125
def _set_method_helper(
11231126
self,

0 commit comments

Comments
 (0)