Skip to content

Commit 47c4045

Browse files
committed
[ModelicaSystem] improve definition of _prepare_inputdata()
1 parent d2d0ead commit 47c4045

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

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

994-
return inputdata
994+
return input_data_from_str
995+
996+
input_data: dict[str, str] = {}
995997

996998
if isinstance(rawinput, str):
997999
warnings.warn(message="The definition of values to set should use a dictionary, "
@@ -1008,20 +1010,21 @@ def prepare_str(str_in: str) -> dict[str, str]:
10081010
category=DeprecationWarning,
10091011
stacklevel=3)
10101012

1011-
inputdata: dict[str, str] = {}
10121013
for item in rawinput:
1013-
inputdata |= prepare_str(item)
1014+
input_data |= prepare_str(item)
10141015

1015-
return inputdata
1016+
return input_data
10161017

10171018
if isinstance(rawinput, dict):
10181019
for key, val in rawinput.items():
10191020
str_val = str(val)
10201021
if ' ' in key or ' ' in str_val:
10211022
raise ModelicaSystemError(f"Spaces not allowed in key/value pairs: {repr(key)} = {repr(val)}!")
1022-
inputdata[key] = str_val
1023+
input_data[key] = str_val
1024+
1025+
return input_data
10231026

1024-
return inputdata
1027+
raise ModelicaSystemError(f"Invalid type of input: {type(rawinput)}")
10251028

10261029
def _set_method_helper(
10271030
self,

0 commit comments

Comments
 (0)