diff --git a/py/math_expression.py b/py/math_expression.py index 497f0e9..53c54e9 100644 --- a/py/math_expression.py +++ b/py/math_expression.py @@ -3,6 +3,15 @@ import math import random import operator as op +# Hack: string type that is always equal in not equal comparisons +class AnyType(str): + def __ne__(self, __value: object) -> bool: + return False + + +# Our any instance wants to be a wildcard string +any = AnyType("*") + operators = { ast.Add: op.add, ast.Sub: op.sub, @@ -98,9 +107,9 @@ class MathExpression: }}), }, "optional": { - "a": ("INT,FLOAT,IMAGE,LATENT", ), - "b": ("INT,FLOAT,IMAGE,LATENT",), - "c": ("INT,FLOAT,IMAGE,LATENT", ), + "a": (any, ), + "b": (any,), + "c": (any, ), }, "hidden": {"extra_pnginfo": "EXTRA_PNGINFO", "prompt": "PROMPT"}, diff --git a/web/js/mathExpression.js b/web/js/mathExpression.js index 2409cf1..d0dde50 100644 --- a/web/js/mathExpression.js +++ b/web/js/mathExpression.js @@ -14,6 +14,15 @@ app.registerExtension({ beforeRegisterNodeDef(nodeType) { if (nodeType.comfyClass === "MathExpression|pysssss") { const onDrawForeground = nodeType.prototype.onDrawForeground; + + nodeType.prototype.onNodeCreated = function() { + // These are typed as any to bypass backend validation + // update frontend to restrict types + for(const input of this.inputs) { + input.type = "INT,FLOAT,IMAGE,LATENT"; + } + } + nodeType.prototype.onDrawForeground = function (ctx) { const r = onDrawForeground?.apply?.(this, arguments);