Officially support wildcard type(*)

This commit is contained in:
huchenlei 2024-12-03 13:35:06 -05:00
parent 5ae9798e89
commit 9bef49ea3b
2 changed files with 28 additions and 0 deletions

View File

@ -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

View File

@ -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())