From a7c59dc3d6a21ba6aad45299b5dbb354c4491e4a Mon Sep 17 00:00:00 2001 From: Jedrzej Kosinski Date: Sat, 19 Jul 2025 20:45:54 -0700 Subject: [PATCH] Removed state from ComfyNodeV3 --- comfy_api/v3/io.py | 63 ----------------------------------- comfy_extras/nodes_v3_test.py | 23 +------------ 2 files changed, 1 insertion(+), 85 deletions(-) diff --git a/comfy_api/v3/io.py b/comfy_api/v3/io.py index a060ccbbc..bbc886b84 100644 --- a/comfy_api/v3/io.py +++ b/comfy_api/v3/io.py @@ -237,67 +237,6 @@ class ComfyTypeIO(ComfyTypeI): ... -class NodeState(ABC): - def __init__(self, node_id: str): - self.node_id = node_id - - @abstractmethod - def get_value(self, key: str): - pass - - @abstractmethod - def set_value(self, key: str, value: Any): - pass - - @abstractmethod - def pop(self, key: str): - pass - - @abstractmethod - def __contains__(self, key: str): - pass - - -class NodeStateLocal(NodeState): - def __init__(self, node_id: str): - super().__init__(node_id) - self.local_state = {} - - def get_value(self, key: str): - return self.local_state.get(key) - - def set_value(self, key: str, value: Any): - self.local_state[key] = value - - def pop(self, key: str): - return self.local_state.pop(key, None) - - def __contains__(self, key: str): - return key in self.local_state - - def __getattr__(self, key: str): - local_state = type(self).__getattribute__(self, "local_state") - if key in local_state: - return local_state[key] - return None - # raise AttributeError(f"'{type(self).__name__}' object has no attribute '{key}'") - - def __setattr__(self, key: str, value: Any): - if key in ['node_id', 'local_state']: - super().__setattr__(key, value) - else: - self.local_state[key] = value - - def __setitem__(self, key: str, value: Any): - self.local_state[key] = value - - def __getitem__(self, key: str): - return self.local_state[key] - - def __delitem__(self, key: str): - del self.local_state[key] - - @comfytype(io_type="BOOLEAN") class Boolean(ComfyTypeIO): Type = bool @@ -1179,7 +1118,6 @@ class _ComfyNodeBaseInternal(ComfyNodeInternal): SCHEMA = None # filled in during execution - state: NodeState = None resources: Resources = None hidden: HiddenHolder = None @@ -1222,7 +1160,6 @@ class _ComfyNodeBaseInternal(ComfyNodeInternal): return [name for name in kwargs if kwargs[name] is None] def __init__(self): - self.local_state: NodeStateLocal = None self.local_resources: ResourcesLocal = None self.__class__.VALIDATE_CLASS() diff --git a/comfy_extras/nodes_v3_test.py b/comfy_extras/nodes_v3_test.py index 799763e7c..9a78f9ae0 100644 --- a/comfy_extras/nodes_v3_test.py +++ b/comfy_extras/nodes_v3_test.py @@ -18,11 +18,7 @@ class XYZ: class V3TestNode(io.ComfyNodeV3): - class State(io.NodeState): - my_str: str - my_int: int - state: State - + # NOTE: this is here just to test that state is not leaking def __init__(self): super().__init__() self.hahajkunless = ";)" @@ -84,23 +80,6 @@ class V3TestNode(io.ComfyNodeV3): @classmethod def execute(cls, image: io.Image.Type, some_int: int, combo: io.Combo.Type, combo2: io.MultiCombo.Type, xyz: XYZ.Type=None, mask: io.Mask.Type=None, **kwargs): - zzz = cls.hidden.prompt - cls.state.my_str = "LOLJK" - expected_int = 123 - if "thing" not in cls.state: - cls.state["thing"] = "hahaha" - yyy = cls.state["thing"] # noqa - del cls.state["thing"] - if cls.state.get_value("int2") is None: - cls.state.set_value("int2", 123) - zzz = cls.state.get_value("int2") # noqa - cls.state.pop("int2") - if cls.state.my_int is None: - cls.state.my_int = expected_int - else: - if cls.state.my_int != expected_int: - raise Exception(f"Explicit state object did not maintain expected value (__getattr__/__setattr__): {cls.state.my_int} != {expected_int}") - #some_int if hasattr(cls, "hahajkunless"): raise Exception("The 'cls' variable leaked instance state between runs!") if hasattr(cls, "doohickey"):