()
| 12 | return not selfset.issubset(otherset) |
| 13 | |
| 14 | def VariantSupport(): |
| 15 | def decorator(cls): |
| 16 | if hasattr(cls, "INPUT_TYPES"): |
| 17 | old_input_types = getattr(cls, "INPUT_TYPES") |
| 18 | def new_input_types(*args, **kwargs): |
| 19 | types = old_input_types(*args, **kwargs) |
| 20 | for category in ["required", "optional"]: |
| 21 | if category not in types: |
| 22 | continue |
| 23 | for key, value in types[category].items(): |
| 24 | if isinstance(value, tuple): |
| 25 | types[category][key] = (MakeSmartType(value[0]),) + value[1:] |
| 26 | return types |
| 27 | setattr(cls, "INPUT_TYPES", new_input_types) |
| 28 | if hasattr(cls, "RETURN_TYPES"): |
| 29 | old_return_types = cls.RETURN_TYPES |
| 30 | setattr(cls, "RETURN_TYPES", tuple(MakeSmartType(x) for x in old_return_types)) |
| 31 | if hasattr(cls, "VALIDATE_INPUTS"): |
| 32 | # Reflection is used to determine what the function signature is, so we can't just change the function signature |
| 33 | raise NotImplementedError("VariantSupport does not support VALIDATE_INPUTS yet") |
| 34 | else: |
| 35 | def validate_inputs(input_types): |
| 36 | inputs = cls.INPUT_TYPES() |
| 37 | for key, value in input_types.items(): |
| 38 | if isinstance(value, SmartType): |
| 39 | continue |
| 40 | if "required" in inputs and key in inputs["required"]: |
| 41 | expected_type = inputs["required"][key][0] |
| 42 | elif "optional" in inputs and key in inputs["optional"]: |
| 43 | expected_type = inputs["optional"][key][0] |
| 44 | else: |
| 45 | expected_type = None |
| 46 | if expected_type is not None and MakeSmartType(value) != expected_type: |
| 47 | return f"Invalid type of {key}: {value} (expected {expected_type})" |
| 48 | return True |
| 49 | setattr(cls, "VALIDATE_INPUTS", validate_inputs) |
| 50 | return cls |
| 51 | return decorator |
| 52 |
nothing calls this directly
no outgoing calls
no test coverage detected