fix cases when expression cannot be evaluated due to type error

This commit is contained in:
2026-06-30 16:51:27 +02:00
parent 974b92ec93
commit 77a829dde2
+6 -1
View File
@@ -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):