ContextExpression
autogen.ContextExpression dataclass
#
A class to evaluate logical expressions using context variables.
PARAMETER | DESCRIPTION |
---|---|
expression | A string containing a logical expression with context variable references. - Variable references use ${var_name} syntax: ${logged_in}, ${attempts} - String literals can use normal quotes: 'hello', "world" - Supported operators: - Logical: not/!, and/&, or/| - Comparison: >, <, >=, <=, ==, != - Supported functions: - len(${var_name}): Gets the length of a list, string, or other collection - Parentheses can be used for grouping - Examples: - "not ${logged_in} and ${is_admin} or ${guest_checkout}" - "!${logged_in} & ${is_admin} | ${guest_checkout}" - "len(${orders}) > 0 & ${user_active}" - "len(${cart_items}) == 0 | ${checkout_started}" TYPE: |
RAISES | DESCRIPTION |
---|---|
SyntaxError | If the expression cannot be parsed |
ValueError | If the expression contains disallowed operations |
evaluate #
Evaluate the expression using the provided context variables.
PARAMETER | DESCRIPTION |
---|---|
context_variables | Dictionary of context variables to use for evaluation |
RETURNS | DESCRIPTION |
---|---|
bool | The result of evaluating the expression TYPE: |