@@ -126,36 +126,39 @@ def arg_set(self, key: str, val: Optional[str | dict] = None) -> None:
126126 """
127127 Set one argument for the executable model.
128128
129- Parameters
130- ----------
131- key : str
132- val : str, None
129+ Args:
130+ key: identifier / argument name to be used for the call of the model executable.
131+ val: value for the given key; None for no value and for key == 'override' a dictionary can be used which
132+ indicates variables to override
133133 """
134134
135- def override2str (value : Any ) -> str :
135+ def override2str (okey : str , oval : Any ) -> str :
136136 """
137137 Convert a value for 'override' to a string taking into account differences between Modelica and Python.
138138 """
139- if isinstance (value , str ):
140- return f"\" { value .strip ()} \" "
141- if isinstance (value , bool ):
142- return 'true' if value else 'false'
143- if isinstance (value , numbers .Number ):
144- return str (value )
145- raise ModelicaSystemError (f"Invalid value type: { type (value )} for key { key } " )
139+ if isinstance (oval , str ):
140+ oval_str = f"\" { oval .strip ()} \" "
141+ elif isinstance (oval , bool ):
142+ oval_str = 'true' if oval else 'false'
143+ elif isinstance (oval , numbers .Number ):
144+ oval_str = str (oval )
145+ else :
146+ raise ModelicaSystemError (f"Invalid value for override key { okey } : { type (oval )} " )
147+
148+ return f"{ okey } ={ oval_str } "
146149
147150 if not isinstance (key , str ):
148151 raise ModelicaSystemError (f"Invalid argument key: { repr (key )} (type: { type (key )} )" )
149152 key = key .strip ()
150153
151154 if key == 'override' and isinstance (val , dict ):
152155 for okey in val :
153- if not isinstance (okey , str ) or not isinstance (val [okey ], (str , numbers .Number )):
156+ if not isinstance (okey , str ) or not isinstance (val [okey ], (str , bool , numbers .Number )):
154157 raise ModelicaSystemError ("Invalid argument for 'override': "
155158 f"{ repr (okey )} = { repr (val [okey ])} " )
156159 self ._arg_override [okey ] = val [okey ]
157160
158- argval = ',' .join ([f" { okey } = { override2str (self . _arg_override [ okey ]) } " for okey in self ._arg_override ])
161+ argval = ',' .join ([override2str (okey = okey , oval = oval ) for okey , oval in self ._arg_override . items () ])
159162 elif val is None :
160163 argval = None
161164 elif isinstance (val , str ):
@@ -182,10 +185,6 @@ def arg_get(self, key: str) -> Optional[str | dict]:
182185 def args_set (self , args : dict [str , Optional [str | dict [str , str ]]]) -> None :
183186 """
184187 Define arguments for the model executable.
185-
186- Parameters
187- ----------
188- args : dict[str, Optional[str | dict[str, str]]]
189188 """
190189 for arg in args :
191190 self .arg_set (key = arg , val = args [arg ])
0 commit comments