diff --git a/pyproject.toml b/pyproject.toml index 67d1d7b..dbb2e4a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "basic_data_handling" -version = "1.1.1" +version = "1.2.0" description = """Basic Python functions for manipulating data that every programmer is used to, lightweight with no additional dependencies. Supported data types: diff --git a/src/basic_data_handling/control_flow_nodes.py b/src/basic_data_handling/control_flow_nodes.py index 9e28150..cc47f08 100644 --- a/src/basic_data_handling/control_flow_nodes.py +++ b/src/basic_data_handling/control_flow_nodes.py @@ -343,6 +343,31 @@ def execute(self, **kwargs: list[Any]) -> tuple[None, Any]: return (None, any_node_output) +class IsConnected(ComfyNodeABC): + """ + Checks if the input is connected. + + This node returns True if the 'input' is connected to another node's output, + and False otherwise. + """ + @classmethod + def INPUT_TYPES(cls): + return { + "optional": { + "input": (IO.ANY, {}), + } + } + + RETURN_TYPES = (IO.BOOLEAN,) + RETURN_NAMES = ("is_connected",) + CATEGORY = "Basic/flow control" + DESCRIPTION = cleandoc(__doc__ or "") + FUNCTION = "execute" + + def execute(self, input: Any = None) -> tuple[bool]: + return (input is not None,) + + NODE_CLASS_MAPPINGS = { "Basic data handling: IfElse": IfElse, "Basic data handling: IfElifElse": IfElifElse, @@ -351,6 +376,7 @@ def execute(self, **kwargs: list[Any]) -> tuple[None, Any]: "Basic data handling: FlowSelect": FlowSelect, "Basic data handling: ForceCalculation": ForceCalculation, "Basic data handling: ExecutionOrder": ExecutionOrder, + "Basic data handling: IsConnected": IsConnected, } NODE_DISPLAY_NAME_MAPPINGS = { @@ -361,4 +387,5 @@ def execute(self, **kwargs: list[Any]) -> tuple[None, Any]: "Basic data handling: FlowSelect": "flow select", "Basic data handling: ForceCalculation": "force calculation", "Basic data handling: ExecutionOrder": "force execution order", + "Basic data handling: IsConnected": "is connected", } diff --git a/tests/test_control_flow_nodes.py b/tests/test_control_flow_nodes.py index 87a0b20..595e3fd 100644 --- a/tests/test_control_flow_nodes.py +++ b/tests/test_control_flow_nodes.py @@ -1,6 +1,6 @@ #import pytest from src.basic_data_handling.control_flow_nodes import ( - IfElse, SwitchCase, IfElifElse, ContinueFlow, FlowSelect, ForceCalculation, ExecutionOrder + IfElse, SwitchCase, IfElifElse, ContinueFlow, FlowSelect, ForceCalculation, ExecutionOrder, IsConnected ) @@ -194,3 +194,14 @@ def test_execution_order(): assert node.execute(other_kwarg="some_val") == (None, []) # with multiple kwargs assert node.execute(**{'any node output': "passthrough_val", "E/O": "ignored"}) == (None, "passthrough_val") + + +def test_is_connected(): + node = IsConnected() + # Test when input is connected (not None) + assert node.execute("connected") == (True,) + assert node.execute(0) == (True,) + assert node.execute(False) == (True,) + # Test when input is NOT connected (None) + assert node.execute(None) == (False,) + assert node.execute() == (False,)