Evaluate a condition expression and return a boolean. Convenience wrapper around ``evaluate_expression`` that coerces the result to bool.
(condition: str, context: Any)
| 481 | |
| 482 | |
| 483 | def evaluate_condition(condition: str, context: Any) -> bool: |
| 484 | """Evaluate a condition expression and return a boolean. |
| 485 | |
| 486 | Convenience wrapper around ``evaluate_expression`` that coerces |
| 487 | the result to bool. |
| 488 | """ |
| 489 | result = evaluate_expression(condition, context) |
| 490 | # Treat plain "false"/"true" strings as booleans so that |
| 491 | # condition: "false" (without {{ }}) behaves as expected. |
| 492 | if isinstance(result, str): |
| 493 | lower = result.lower() |
| 494 | if lower == "false": |
| 495 | return False |
| 496 | if lower == "true": |
| 497 | return True |
| 498 | return bool(result) |