Skip to content

Commit d9643e5

Browse files
committed
[ModelicaSystem] add ModelicaSystemError() for unhandled final else cases
there are a lot of functions which check the type of the input; this is done by if ... elif ... - however, invalid input is not catched, i.e. there is *NO* return value define (would be None) if the input is not matching any of the if branches
1 parent 64b72f3 commit d9643e5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

OMPython/ModelicaSystem.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ def getQuantities(self, names=None): # 3
430430
elif isinstance(names, list):
431431
return [x for y in names for x in self.quantitiesList if x["name"] == y]
432432

433+
raise ModelicaSystemError("Unhandled input for getQuantities()")
434+
433435
def getContinuous(self, names=None): # 4
434436
"""
435437
This method returns dict. The key is continuous names and value is corresponding continuous value.
@@ -474,6 +476,8 @@ def getContinuous(self, names=None): # 4
474476
raise ModelicaSystemError(f"OM error: {i} is not continuous")
475477
return valuelist
476478

479+
raise ModelicaSystemError("Unhandled input for getContinous()")
480+
477481
def getParameters(self, names: Optional[str | list[str]] = None) -> dict[str, str] | list[str]: # 5
478482
"""Get parameter values.
479483
@@ -503,6 +507,8 @@ def getParameters(self, names: Optional[str | list[str]] = None) -> dict[str, st
503507
elif isinstance(names, list):
504508
return ([self.paramlist.get(x, "NotExist") for x in names])
505509

510+
raise ModelicaSystemError("Unhandled input for getParameters()")
511+
506512
def getInputs(self, names: Optional[str | list[str]] = None) -> dict | list: # 6
507513
"""Get input values.
508514
@@ -537,6 +543,8 @@ def getInputs(self, names: Optional[str | list[str]] = None) -> dict | list: #
537543
elif isinstance(names, list):
538544
return ([self.inputlist.get(x, "NotExist") for x in names])
539545

546+
raise ModelicaSystemError("Unhandled input for getInputs()")
547+
540548
def getOutputs(self, names: Optional[str | list[str]] = None): # 7
541549
"""Get output values.
542550
@@ -605,6 +613,8 @@ def getOutputs(self, names: Optional[str | list[str]] = None): # 7
605613
return (i, "is not Output")
606614
return valuelist
607615

616+
raise ModelicaSystemError("Unhandled input for getOutputs()")
617+
608618
def getSimulationOptions(self, names=None): # 8
609619
"""
610620
This method returns dict. The key is simulation option names and value is corresponding simulation option value.
@@ -621,6 +631,8 @@ def getSimulationOptions(self, names=None): # 8
621631
elif isinstance(names, list):
622632
return ([self.simulateOptions.get(x, "NotExist") for x in names])
623633

634+
raise ModelicaSystemError("Unhandled input for getSimulationOptions()")
635+
624636
def getLinearizationOptions(self, names=None): # 9
625637
"""
626638
This method returns dict. The key is linearize option names and value is corresponding linearize option value.
@@ -637,6 +649,8 @@ def getLinearizationOptions(self, names=None): # 9
637649
elif isinstance(names, list):
638650
return ([self.linearOptions.get(x, "NotExist") for x in names])
639651

652+
raise ModelicaSystemError("Unhandled input for getLinearizationOptions()")
653+
640654
def getOptimizationOptions(self, names=None): # 10
641655
"""
642656
usage:
@@ -651,6 +665,8 @@ def getOptimizationOptions(self, names=None): # 10
651665
elif isinstance(names, list):
652666
return ([self.optimizeOptions.get(x, "NotExist") for x in names])
653667

668+
raise ModelicaSystemError("Unhandled input for getOptimizationOptions()")
669+
654670
def get_exe_file(self) -> pathlib.Path:
655671
"""Get path to model executable."""
656672
if platform.system() == "Windows":
@@ -773,12 +789,16 @@ def getSolutions(self, varList=None, resultfile=None): # 12
773789
self.sendExpression("closeSimulationResultFile()")
774790
return npRes
775791

792+
raise ModelicaSystemError("Unhandled input for getSolutions()")
793+
776794
def strip_space(self, name):
777795
if isinstance(name, str):
778796
return name.replace(" ", "")
779797
elif isinstance(name, list):
780798
return [x.replace(" ", "") for x in name]
781799

800+
raise ModelicaSystemError("Unhandled input for strip_space()")
801+
782802
def setMethodHelper(self, args1, args2, args3, args4=None):
783803
"""
784804
Helper function for setParameter(),setContinuous(),setSimulationOptions(),setLinearizationOption(),setOptimizationOption()

0 commit comments

Comments
 (0)