From ea93669a82212674ee17cade8bf960d0892119a0 Mon Sep 17 00:00:00 2001 From: Antonio Cordero Balcazar Date: Thu, 30 Apr 2026 09:44:12 +0200 Subject: [PATCH] * Support comparisons between floats and ints. --- ppp_tree.py | 20 ++++++++++++++------ tests/tests_varcomms.py | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/ppp_tree.py b/ppp_tree.py index a604833..e8aa0d2 100644 --- a/ppp_tree.py +++ b/ppp_tree.py @@ -338,12 +338,20 @@ class TreeProcessor(lark.visitors.Interpreter): if operand1 is None or operand2 is None: self.warn_or_stop(f"Undefined value used in comparison: '{escape_single_quotes(desc)}'") return False - if ( - isinstance(operand1, (str, int, float, bool)) - and isinstance(operand2, (str, int, float, bool)) - and operand1.__class__ != operand2.__class__ - ): - self.warn_or_stop(f"Mixed type values used in comparison: '{escape_single_quotes(desc)}'") + compatible_types = [ + (str, str), + (int, int), + (float, float), + (bool, bool), + (int, float), + (float, int), + (str, list), + (int, list), + (float, list), + (bool, list), + ] + if not any(isinstance(operand1, t1) and isinstance(operand2, t2) for t1, t2 in compatible_types): + self.warn_or_stop(f"Mixed type values ({type(operand1).__name__}, {type(operand2).__name__}) used in comparison: '{escape_single_quotes(desc)}'") return False return operation(operand1, operand2) diff --git a/tests/tests_varcomms.py b/tests/tests_varcomms.py index 39a5348..535cb01 100644 --- a/tests/tests_varcomms.py +++ b/tests/tests_varcomms.py @@ -195,6 +195,15 @@ class TestVarCommands(TestPromptPostProcessorBase): variables={"v1[]": "val1, val2, val3", "v1[#]": "3"}, ) + def test_array_variable_10(self): # array variable set with expanded values from wildcards in command format + self.process( + PromptPair( + "*__yaml/wildcard1__*__yaml/wildcard2__${v1[2]:defval}", + "", + ), + PromptPair("choice3", ""), + variables={"v1[]": "choice2, choice1, choice3, choice1"}, + ) # Operator tests @@ -632,6 +641,18 @@ class TestVarCommands(TestPromptPostProcessorBase): PromptPair("OK", ""), ) + # Float values + + def test_float_value(self): + self.process( + PromptPair( + "${a=1.5}OKnot OK", + "", + ), + PromptPair("OK", ""), + ) + + # NaN/undefined variable integer comparison tests def test_cmd_if_undefined_var_int_compare_warn(self): # undefined var integer compare with on_warning=warn