Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 27 additions & 0 deletions src/basic_data_handling/control_flow_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = {
Expand All @@ -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",
}
13 changes: 12 additions & 1 deletion tests/test_control_flow_nodes.py
Original file line number Diff line number Diff line change
@@ -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
)


Expand Down Expand Up @@ -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,)