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
32 changes: 32 additions & 0 deletions src/basic_data_handling/data_list_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,36 @@ def create_list(self, **kwargs: list[Any]) -> tuple[list]:
return (values[:-1],)


class DataListListCreate(ComfyNodeABC):
"""
Creates a new Data List from items.

This node creates and returns a Data List. The list of items is dynamically
extended based on the number of inputs provided.

Each input can be a list, so you'll get a list of lists.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"optional": ContainsDynamicDict({
"item_0": (IO.ANY, {"_dynamic": "number", "widgetType": "STRING"}),
})
}

RETURN_TYPES = (IO.ANY,)
RETURN_NAMES = ("list",)
CATEGORY = "Basic/Data List"
DESCRIPTION = cleandoc(__doc__ or "")
FUNCTION = "create_list"
OUTPUT_IS_LIST = (True,)
INPUT_IS_LIST = True

def create_list(self, **kwargs: list[Any]) -> tuple[list]:
values = list(kwargs.values())
return (values[:-1],)


class DataListCreateFromBoolean(ComfyNodeABC):
"""
Creates a new Data List from BOOLEAN items.
Expand Down Expand Up @@ -1087,6 +1117,7 @@ def convert(self, **kwargs: list[Any]) -> tuple[set[Any]]:

NODE_CLASS_MAPPINGS = {
"Basic data handling: DataListCreate": DataListCreate,
"Basic data handling: DataListListCreate": DataListListCreate,
"Basic data handling: DataListCreateFromBoolean": DataListCreateFromBoolean,
"Basic data handling: DataListCreateFromFloat": DataListCreateFromFloat,
"Basic data handling: DataListCreateFromInt": DataListCreateFromInt,
Expand Down Expand Up @@ -1124,6 +1155,7 @@ def convert(self, **kwargs: list[Any]) -> tuple[set[Any]]:

NODE_DISPLAY_NAME_MAPPINGS = {
"Basic data handling: DataListCreate": "create Data List",
"Basic data handling: DataListListCreate": "create Data List of Lists",
"Basic data handling: DataListCreateFromBoolean": "create Data List from BOOLEANs",
"Basic data handling: DataListCreateFromFloat": "create Data List from FLOATs",
"Basic data handling: DataListCreateFromInt": "create Data List from INTs",
Expand Down
15 changes: 15 additions & 0 deletions tests/test_data_list_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
DataListInsert,
DataListLast,
DataListLength,
DataListListCreate,
DataListMax,
DataListMin,
DataListPop,
Expand Down Expand Up @@ -239,6 +240,20 @@ def test_create_from_string():
assert node.create_list(_dynamic_number=0) == ([],)


def test_list_create():
node = DataListListCreate()
# Testing with string values
assert (node.create_list(item_0=["hello", "world"], item_1=["bye", "bye!"], _dynamic_number=2) ==
([["hello", "world"], ["bye", "bye!"]],))

# Testing with mixed values
assert (node.create_list(item_0=[123, 456], item_1=[True, False], _dynamic_number=2) ==
([[123, 456], [True, False]],))

# Testing with empty list
assert node.create_list(_dynamic_number=0) == ([],)


def test_pop_random():
node = DataListPopRandom()
result_list, item = node.pop_random_element(list=[1])
Expand Down