fix cases when expression cannot be evaluated due to type error
This commit is contained in:
+6
-1
@@ -274,7 +274,12 @@ class SafeExpression:
|
||||
def evaluate(self, variables: Mapping[str, int | float]) -> int | float | bool:
|
||||
# normalize to downcased variable names
|
||||
variables = {k.lower(): v for k,v in variables.items()}
|
||||
return self._eval(self.tree.body, variables)
|
||||
try:
|
||||
return self._eval(self.tree.body, variables)
|
||||
except TypeError:
|
||||
return False
|
||||
except:
|
||||
raise
|
||||
|
||||
def _eval(self, node: ast.AST, variables: Mapping[str, int | float]):
|
||||
if isinstance(node, ast.Constant):
|
||||
|
||||
Reference in New Issue
Block a user