fix: remove whitespace and deprecation cruft

Amp-Thread-ID: https://ampcode.com/threads/T-019c2be8-0b34-747e-b1f7-20a1a1e6c9df
This commit is contained in:
bymyself
2026-02-04 19:50:53 -08:00
parent 3f18652588
commit 8db3d29298
3 changed files with 13 additions and 55 deletions

View File

@@ -8,36 +8,30 @@ if TYPE_CHECKING:
class NodeReplaceManager:
"""
Manages node replacement registrations.
Stores replacements as instance state (not module-level globals) to support
process isolation via pyisolate, where extensions run in separate processes
and communicate via RPC.
"""
"""Manages node replacement registrations."""
def __init__(self):
self._replacements: dict[str, list[NodeReplace]] = {}
def register(self, node_replace: NodeReplace):
"""Register a node replacement mapping."""
self._replacements.setdefault(node_replace.old_node_id, []).append(node_replace)
def get_replacement(self, old_node_id: str) -> list[NodeReplace] | None:
"""Get replacements for an old node ID."""
return self._replacements.get(old_node_id)
def has_replacement(self, old_node_id: str) -> bool:
"""Check if a replacement exists for an old node ID."""
return old_node_id in self._replacements
def as_dict(self):
"""Serialize all replacements to dict."""
return {
k: [v.as_dict() for v in v_list]
k: [v.as_dict() for v in v_list]
for k, v_list in self._replacements.items()
}
def add_routes(self, routes):
@routes.get("/node_replacements")
async def get_node_replacements(request):

View File

@@ -24,16 +24,7 @@ class ComfyAPI_latest(ComfyAPIBase):
class NodeReplacement(ProxiedSingleton):
async def register(self, node_replace: 'node_replace.NodeReplace') -> None:
"""
Register a node replacement mapping.
This async method supports process isolation via pyisolate, where
extensions run in separate processes. The call is RPC'd to the host
process where PromptServer and NodeReplaceManager live.
Args:
node_replace: A NodeReplace object defining the old->new mapping
"""
"""Register a node replacement mapping."""
from server import PromptServer
PromptServer.instance.node_replace_manager.register(node_replace)

View File

@@ -1,27 +1,8 @@
from __future__ import annotations
import warnings
from typing import Any
def register_node_replacement(node_replace: NodeReplace):
"""
Register node replacement.
.. deprecated::
Use ``ComfyAPI.node_replacement.register()`` instead.
This synchronous function does not work with process isolation (pyisolate).
"""
warnings.warn(
"register_node_replacement() is deprecated. "
"Use 'await ComfyAPI.node_replacement.register()' instead for pyisolate compatibility.",
DeprecationWarning,
stacklevel=2
)
from server import PromptServer
PromptServer.instance.node_replace_manager.register(node_replace)
class NodeReplace:
"""
Defines a possible node replacement, mapping inputs and outputs of the old node to the new node.
@@ -42,9 +23,7 @@ class NodeReplace:
self.output_mapping = output_mapping
def as_dict(self):
"""
Create serializable representation of the node replacement.
"""
"""Create serializable representation of the node replacement."""
return {
"new_node_id": self.new_node_id,
"old_node_id": self.old_node_id,
@@ -70,9 +49,7 @@ class InputMap:
}
class OldId(_Assign):
"""
Connect the input of the old node with given id to new node when replacing.
"""
"""Connect the input of the old node with given id to new node when replacing."""
def __init__(self, old_id: str):
super().__init__("old_id")
self.old_id = old_id
@@ -83,9 +60,7 @@ class InputMap:
}
class SetValue(_Assign):
"""
Use the given value for the input of the new node when replacing; assumes input is a widget.
"""
"""Use the given value for the input of the new node when replacing; assumes input is a widget."""
def __init__(self, value: Any):
super().__init__("set_value")
self.value = value
@@ -107,9 +82,7 @@ class InputMap:
class OutputMap:
"""
Map outputs of node replacement via indexes, as that's how outputs are stored.
"""
"""Map outputs of node replacement via indexes, as that's how outputs are stored."""
def __init__(self, new_idx: int, old_idx: int):
self.new_idx = new_idx
self.old_idx = old_idx