CoolFace
Apppublic

nef7/my-comfyui-workflow

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
validation.py40 linesDownload Raw Back to comfy_execution
1from __future__ import annotations2 3 4def validate_node_input(5    received_type: str, input_type: str, strict: bool = False6) -> 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 is13      "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 immediately22    # Use pre-union behaviour: inverse of `__ne__`23    if not received_type != input_type:24        return True25 26    # Not equal, and not strings27    if not isinstance(received_type, str) or not isinstance(input_type, str):28        return False29 30    # Split the type strings into sets for comparison31    received_types = set(t.strip() for t in received_type.split(","))32    input_types = set(t.strip() for t in input_type.split(","))33 34    if strict:35        # In strict mode, all received types must be in the input types36        return received_types.issubset(input_types)37    else:38        # In non-strict mode, there must be at least one type in common39        return len(received_types.intersection(input_types)) > 040