diff --git a/src/basic_data_handling/data_list_nodes.py b/src/basic_data_handling/data_list_nodes.py index 846aad3..f7dc76d 100644 --- a/src/basic_data_handling/data_list_nodes.py +++ b/src/basic_data_handling/data_list_nodes.py @@ -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. @@ -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, @@ -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", diff --git a/tests/test_data_list_nodes.py b/tests/test_data_list_nodes.py index 6560716..aa6d9e4 100644 --- a/tests/test_data_list_nodes.py +++ b/tests/test_data_list_nodes.py @@ -20,6 +20,7 @@ DataListInsert, DataListLast, DataListLength, + DataListListCreate, DataListMax, DataListMin, DataListPop, @@ -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])