Merge pull request #41 from StableLlama/add_isConnected
Add new node: check whether the input is connected
This commit is contained in:
+1
-1
@@ -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:
|
||||
|
||||
@@ -343,6 +343,31 @@ class ExecutionOrder(ComfyNodeABC):
|
||||
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 @@ NODE_CLASS_MAPPINGS = {
|
||||
"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 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"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",
|
||||
}
|
||||
|
||||
@@ -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,)
|
||||
|
||||
Reference in New Issue
Block a user