mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-07-27 16:26:39 +00:00
Removed state from ComfyNodeV3
This commit is contained in:
parent
96d317b3e2
commit
a7c59dc3d6
@ -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")
|
@comfytype(io_type="BOOLEAN")
|
||||||
class Boolean(ComfyTypeIO):
|
class Boolean(ComfyTypeIO):
|
||||||
Type = bool
|
Type = bool
|
||||||
@ -1179,7 +1118,6 @@ class _ComfyNodeBaseInternal(ComfyNodeInternal):
|
|||||||
SCHEMA = None
|
SCHEMA = None
|
||||||
|
|
||||||
# filled in during execution
|
# filled in during execution
|
||||||
state: NodeState = None
|
|
||||||
resources: Resources = None
|
resources: Resources = None
|
||||||
hidden: HiddenHolder = None
|
hidden: HiddenHolder = None
|
||||||
|
|
||||||
@ -1222,7 +1160,6 @@ class _ComfyNodeBaseInternal(ComfyNodeInternal):
|
|||||||
return [name for name in kwargs if kwargs[name] is None]
|
return [name for name in kwargs if kwargs[name] is None]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.local_state: NodeStateLocal = None
|
|
||||||
self.local_resources: ResourcesLocal = None
|
self.local_resources: ResourcesLocal = None
|
||||||
self.__class__.VALIDATE_CLASS()
|
self.__class__.VALIDATE_CLASS()
|
||||||
|
|
||||||
|
@ -18,11 +18,7 @@ class XYZ:
|
|||||||
|
|
||||||
|
|
||||||
class V3TestNode(io.ComfyNodeV3):
|
class V3TestNode(io.ComfyNodeV3):
|
||||||
class State(io.NodeState):
|
# NOTE: this is here just to test that state is not leaking
|
||||||
my_str: str
|
|
||||||
my_int: int
|
|
||||||
state: State
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.hahajkunless = ";)"
|
self.hahajkunless = ";)"
|
||||||
@ -84,23 +80,6 @@ class V3TestNode(io.ComfyNodeV3):
|
|||||||
|
|
||||||
@classmethod
|
@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):
|
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"):
|
if hasattr(cls, "hahajkunless"):
|
||||||
raise Exception("The 'cls' variable leaked instance state between runs!")
|
raise Exception("The 'cls' variable leaked instance state between runs!")
|
||||||
if hasattr(cls, "doohickey"):
|
if hasattr(cls, "doohickey"):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user