From 9bef49ea3b319fbf4c6ced74fcd174b87ba1add3 Mon Sep 17 00:00:00 2001 From: huchenlei Date: Tue, 3 Dec 2024 13:35:06 -0500 Subject: [PATCH] Officially support wildcard type(*) --- comfy_execution/validation.py | 4 ++++ .../validate_node_input_test.py | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/comfy_execution/validation.py b/comfy_execution/validation.py index 43fb6426d..13c8f82c7 100644 --- a/comfy_execution/validation.py +++ b/comfy_execution/validation.py @@ -16,6 +16,10 @@ def validate_node_input( For example, if received_type is "STRING,BOOLEAN" and input_type is "STRING,INT", this will return True. """ + # If either type is *, we allow any type + if any(t == "*" for t in [received_type, input_type]): + return True + # If the types are exactly the same, we can return immediately if received_type == input_type: return True diff --git a/tests-unit/execution_test/validate_node_input_test.py b/tests-unit/execution_test/validate_node_input_test.py index d6605e97f..2a01deae9 100644 --- a/tests-unit/execution_test/validate_node_input_test.py +++ b/tests-unit/execution_test/validate_node_input_test.py @@ -73,3 +73,27 @@ def test_single_vs_multiple(): def test_parametrized_cases(received, input_type, strict, expected): """Parametrized test cases for various scenarios""" assert validate_node_input(received, input_type, strict) == expected + + +# https://github.com/FredBill1/comfyui-fb-utils/blob/main/core/types.py +class AnyType(str): + """A special class that is always equal in not equal comparisons.""" + + def __eq__(self, _) -> bool: + return True + + def __ne__(self, __value: object) -> bool: + return False + + +def test_wildcard(): + """Test behavior with wildcard""" + assert validate_node_input("*", "STRING,INT") + assert validate_node_input("STRING,INT", "*") + assert validate_node_input("*", "*") + + # AnyType was previous wildcard hack used by many custom nodes. + # AnyType should be treated as a wildcard. + assert validate_node_input(AnyType(), "STRING,INT") + assert validate_node_input("STRING,INT", AnyType()) + assert validate_node_input(AnyType(), AnyType())