Skip to content

Commit c8bb129

Browse files
authored
Merge pull request #30 from set-soft/data_list_list
[Added] DataListListCreate node
2 parents 8c44769 + c5c7337 commit c8bb129

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/basic_data_handling/data_list_nodes.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,36 @@ def create_list(self, **kwargs: list[Any]) -> tuple[list]:
4545
return (values[:-1],)
4646

4747

48+
class DataListListCreate(ComfyNodeABC):
49+
"""
50+
Creates a new Data List from items.
51+
52+
This node creates and returns a Data List. The list of items is dynamically
53+
extended based on the number of inputs provided.
54+
55+
Each input can be a list, so you'll get a list of lists.
56+
"""
57+
@classmethod
58+
def INPUT_TYPES(cls):
59+
return {
60+
"optional": ContainsDynamicDict({
61+
"item_0": (IO.ANY, {"_dynamic": "number", "widgetType": "STRING"}),
62+
})
63+
}
64+
65+
RETURN_TYPES = (IO.ANY,)
66+
RETURN_NAMES = ("list",)
67+
CATEGORY = "Basic/Data List"
68+
DESCRIPTION = cleandoc(__doc__ or "")
69+
FUNCTION = "create_list"
70+
OUTPUT_IS_LIST = (True,)
71+
INPUT_IS_LIST = True
72+
73+
def create_list(self, **kwargs: list[Any]) -> tuple[list]:
74+
values = list(kwargs.values())
75+
return (values[:-1],)
76+
77+
4878
class DataListCreateFromBoolean(ComfyNodeABC):
4979
"""
5080
Creates a new Data List from BOOLEAN items.
@@ -1087,6 +1117,7 @@ def convert(self, **kwargs: list[Any]) -> tuple[set[Any]]:
10871117

10881118
NODE_CLASS_MAPPINGS = {
10891119
"Basic data handling: DataListCreate": DataListCreate,
1120+
"Basic data handling: DataListListCreate": DataListListCreate,
10901121
"Basic data handling: DataListCreateFromBoolean": DataListCreateFromBoolean,
10911122
"Basic data handling: DataListCreateFromFloat": DataListCreateFromFloat,
10921123
"Basic data handling: DataListCreateFromInt": DataListCreateFromInt,
@@ -1124,6 +1155,7 @@ def convert(self, **kwargs: list[Any]) -> tuple[set[Any]]:
11241155

11251156
NODE_DISPLAY_NAME_MAPPINGS = {
11261157
"Basic data handling: DataListCreate": "create Data List",
1158+
"Basic data handling: DataListListCreate": "create Data List of Lists",
11271159
"Basic data handling: DataListCreateFromBoolean": "create Data List from BOOLEANs",
11281160
"Basic data handling: DataListCreateFromFloat": "create Data List from FLOATs",
11291161
"Basic data handling: DataListCreateFromInt": "create Data List from INTs",

tests/test_data_list_nodes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
DataListInsert,
2121
DataListLast,
2222
DataListLength,
23+
DataListListCreate,
2324
DataListMax,
2425
DataListMin,
2526
DataListPop,
@@ -239,6 +240,20 @@ def test_create_from_string():
239240
assert node.create_list(_dynamic_number=0) == ([],)
240241

241242

243+
def test_list_create():
244+
node = DataListListCreate()
245+
# Testing with string values
246+
assert (node.create_list(item_0=["hello", "world"], item_1=["bye", "bye!"], _dynamic_number=2) ==
247+
([["hello", "world"], ["bye", "bye!"]],))
248+
249+
# Testing with mixed values
250+
assert (node.create_list(item_0=[123, 456], item_1=[True, False], _dynamic_number=2) ==
251+
([[123, 456], [True, False]],))
252+
253+
# Testing with empty list
254+
assert node.create_list(_dynamic_number=0) == ([],)
255+
256+
242257
def test_pop_random():
243258
node = DataListPopRandom()
244259
result_list, item = node.pop_random_element(list=[1])

0 commit comments

Comments
 (0)