MCPcopy Create free account
hub / github.com/Comfy-Org/ComfyUI / validate_node_input

Function validate_node_input

comfy_execution/validation.py:4–58  ·  view source on GitHub ↗

received_type and input_type are both strings of the form "T1,T2,...". If strict is True, the input_type must contain the received_type. For example, if received_type is "STRING" and input_type is "STRING,INT", this will return True. But if received_type is "STRING,INT" and inp

(
    received_type: str, input_type: str, strict: bool = False
)

Source from the content-addressed store, hash-verified

2
3
4def validate_node_input(
5 received_type: str, input_type: str, strict: bool = False
6) -> bool:
7 """
8 received_type and input_type are both strings of the form "T1,T2,...".
9
10 If strict is True, the input_type must contain the received_type.
11 For example, if received_type is "STRING" and input_type is "STRING,INT",
12 this will return True. But if received_type is "STRING,INT" and input_type is
13 "INT", this will return False.
14
15 If strict is False, the input_type must have overlap with the received_type.
16 For example, if received_type is "STRING,BOOLEAN" and input_type is "STRING,INT",
17 this will return True.
18
19 Supports pre-union type extension behaviour of ``__ne__`` overrides.
20 """
21 # If the types are exactly the same, we can return immediately
22 # Use pre-union behaviour: inverse of `__ne__`
23 # NOTE: this lets legacy '*' Any types work that override the __ne__ method of the str class.
24 if not received_type != input_type:
25 return True
26
27 # If one of the types is '*', we can return True immediately; this is the 'Any' type.
28 if received_type == IO.AnyType.io_type or input_type == IO.AnyType.io_type:
29 return True
30
31 # If the received type or input_type is a MatchType, we can return True immediately;
32 # validation for this is handled by the frontend
33 if received_type == IO.MatchType.io_type or input_type == IO.MatchType.io_type:
34 return True
35
36 # This accounts for some custom nodes that output lists of options as the type;
37 # if we ever want to break them on purpose, this can be removed
38 if isinstance(received_type, list) and input_type == IO.Combo.io_type:
39 return True
40
41 # Not equal, and not strings
42 if not isinstance(received_type, str) or not isinstance(input_type, str):
43 return False
44
45 # Split the type strings into sets for comparison
46 received_types = set(t.strip() for t in received_type.split(","))
47 input_types = set(t.strip() for t in input_type.split(","))
48
49 # If any of the types is '*', we can return True immediately; this is the 'Any' type.
50 if IO.AnyType.io_type in received_types or IO.AnyType.io_type in input_types:
51 return True
52
53 if strict:
54 # In strict mode, all received types must be in the input types
55 return received_types.issubset(input_types)
56 else:
57 # In non-strict mode, there must be at least one type in common
58 return len(received_types.intersection(input_types)) > 0

Callers 11

validate_inputsFunction · 0.90
test_exact_matchFunction · 0.90
test_strict_modeFunction · 0.90
test_non_strict_modeFunction · 0.90
test_whitespace_handlingFunction · 0.90
test_empty_stringsFunction · 0.90
test_single_vs_multipleFunction · 0.90
test_non_stringFunction · 0.90
test_ne_overrideFunction · 0.90
test_ne_custom_overrideFunction · 0.90
test_parametrized_casesFunction · 0.90

Calls

no outgoing calls

Tested by 10

test_exact_matchFunction · 0.72
test_strict_modeFunction · 0.72
test_non_strict_modeFunction · 0.72
test_whitespace_handlingFunction · 0.72
test_empty_stringsFunction · 0.72
test_single_vs_multipleFunction · 0.72
test_non_stringFunction · 0.72
test_ne_overrideFunction · 0.72
test_ne_custom_overrideFunction · 0.72
test_parametrized_casesFunction · 0.72