From 43f24409726709bba06530bd62059e31baaf0b95 Mon Sep 17 00:00:00 2001 From: LaVie024 <62406970+LaVie024@users.noreply.github.com> Date: Sun, 29 Mar 2026 22:40:59 +0000 Subject: [PATCH 1/2] Add Boolean support to math expressions --- comfy_extras/nodes_math.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/comfy_extras/nodes_math.py b/comfy_extras/nodes_math.py index 6417bacf1..96c839fe4 100644 --- a/comfy_extras/nodes_math.py +++ b/comfy_extras/nodes_math.py @@ -63,7 +63,7 @@ class MathExpressionNode(io.ComfyNode): @classmethod def define_schema(cls) -> io.Schema: autogrow = io.Autogrow.TemplateNames( - input=io.MultiType.Input("value", [io.Float, io.Int]), + input=io.MultiType.Input("value", [io.Float, io.Int, io.Boolean]), names=list(string.ascii_lowercase), min=1, ) @@ -82,6 +82,7 @@ class MathExpressionNode(io.ComfyNode): outputs=[ io.Float.Output(display_name="FLOAT"), io.Int.Output(display_name="INT"), + io.Boolean.Output(display_name="BOOL"), ], ) @@ -97,7 +98,7 @@ class MathExpressionNode(io.ComfyNode): result = simple_eval(expression, names=context, functions=MATH_FUNCTIONS) # bool check must come first because bool is a subclass of int in Python - if isinstance(result, bool) or not isinstance(result, (int, float)): + if not isinstance(result, (int, float)): raise ValueError( f"Math Expression '{expression}' must evaluate to a numeric result, " f"got {type(result).__name__}: {result!r}" @@ -106,7 +107,7 @@ class MathExpressionNode(io.ComfyNode): raise ValueError( f"Math Expression '{expression}' produced a non-finite result: {result}" ) - return io.NodeOutput(float(result), int(result)) + return io.NodeOutput(float(result), int(result), bool(result)) class MathExtension(ComfyExtension): From e1f652a81cae5cfc115ecd4fc33bf9210877c106 Mon Sep 17 00:00:00 2001 From: LaVie024 <62406970+LaVie024@users.noreply.github.com> Date: Mon, 4 May 2026 04:53:09 +0000 Subject: [PATCH 2/2] Change boolean result test to assert values --- tests-unit/comfy_extras_test/nodes_math_test.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests-unit/comfy_extras_test/nodes_math_test.py b/tests-unit/comfy_extras_test/nodes_math_test.py index fa4cdcac3..714e37c32 100644 --- a/tests-unit/comfy_extras_test/nodes_math_test.py +++ b/tests-unit/comfy_extras_test/nodes_math_test.py @@ -124,9 +124,11 @@ class TestMathExpressionExecute: with pytest.raises(Exception, match="not defined"): self._exec("str(a)", a=42) - def test_boolean_result_raises(self): - with pytest.raises(ValueError, match="got bool"): - self._exec("a > b", a=5, b=3) + def test_boolean_result(self): + result = self._exec("a > b", a=5, b=3) + assert result[2] is True + result = self._exec("a > b", a=3, b=5) + assert result[2] is False def test_empty_expression_raises(self): with pytest.raises(ValueError, match="Expression cannot be empty"):