Skip to content

Commit 541a314

Browse files
committed
feat(configuration_steps): Support lists and the "in" operator
1 parent 83c093b commit 541a314

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

ardupilot_methodic_configurator/data_model_safe_evaluator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from types import MappingProxyType
1616
from typing import Union, cast
1717

18-
from simpleeval import InvalidExpression, simple_eval
18+
from simpleeval import EvalWithCompoundTypes, InvalidExpression
1919

2020
SAFE_FUNCTIONS = MappingProxyType(
2121
{
@@ -68,7 +68,8 @@ def safe_evaluate(expression: str, variables: dict) -> Union[int, float, str]:
6868
6969
"""
7070
try:
71-
return cast("Union[int, float, str]", simple_eval(expression, names=variables, functions=SAFE_FUNCTIONS))
71+
evaluator = EvalWithCompoundTypes(names=variables, functions=dict(SAFE_FUNCTIONS))
72+
return cast("Union[int, float, str]", evaluator.eval(expression))
7273
except (
7374
InvalidExpression,
7475
SyntaxError,

0 commit comments

Comments
 (0)