From c48095d9c6912770265c25d3129102293a4ce5a3 Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Tue, 14 Oct 2025 09:12:55 +0800 Subject: [PATCH] feat: replace IO type imports with string literals Remove direct imports of IO type constants from comfy.comfy_types and replace them with string literals "STRING" in input type definitions and return types. This improves code portability and reduces dependency on external type definitions. Changes made across multiple files: - Remove `from comfy.comfy_types import IO` imports - Replace `IO.STRING` with "STRING" in INPUT_TYPES and RETURN_TYPES - Move CLIPTextEncode import to function scope in prompt.py for better dependency management This refactor maintains the same functionality while making the code more self-contained and reducing external dependencies. --- py/nodes/lora_loader.py | 9 ++++----- py/nodes/lora_stacker.py | 5 ++--- py/nodes/prompt.py | 2 +- py/nodes/trigger_word_toggle.py | 1 - py/nodes/wanvideo_lora_select.py | 5 ++--- py/nodes/wanvideo_lora_select_from_text.py | 7 +++---- 6 files changed, 12 insertions(+), 17 deletions(-) diff --git a/py/nodes/lora_loader.py b/py/nodes/lora_loader.py index d431c263..9a00816f 100644 --- a/py/nodes/lora_loader.py +++ b/py/nodes/lora_loader.py @@ -1,7 +1,6 @@ import logging import re from nodes import LoraLoader -from comfy.comfy_types import IO # type: ignore from ..utils.utils import get_lora_info from .utils import FlexibleOptionalInputType, any_type, extract_lora_name, get_loras_list, nunchaku_load_lora @@ -17,7 +16,7 @@ class LoraManagerLoader: "required": { "model": ("MODEL",), # "clip": ("CLIP",), - "text": (IO.STRING, { + "text": ("STRING", { "multiline": True, "pysssss.autocomplete": False, "dynamicPrompts": True, @@ -28,7 +27,7 @@ class LoraManagerLoader: "optional": FlexibleOptionalInputType(any_type), } - RETURN_TYPES = ("MODEL", "CLIP", IO.STRING, IO.STRING) + RETURN_TYPES = ("MODEL", "CLIP", "STRING", "STRING") RETURN_NAMES = ("MODEL", "CLIP", "trigger_words", "loaded_loras") FUNCTION = "load_loras" @@ -141,7 +140,7 @@ class LoraManagerTextLoader: return { "required": { "model": ("MODEL",), - "lora_syntax": (IO.STRING, { + "lora_syntax": ("STRING", { "defaultInput": True, "forceInput": True, "tooltip": "Format: separated by spaces or punctuation" @@ -153,7 +152,7 @@ class LoraManagerTextLoader: } } - RETURN_TYPES = ("MODEL", "CLIP", IO.STRING, IO.STRING) + RETURN_TYPES = ("MODEL", "CLIP", "STRING", "STRING") RETURN_NAMES = ("MODEL", "CLIP", "trigger_words", "loaded_loras") FUNCTION = "load_loras_from_text" diff --git a/py/nodes/lora_stacker.py b/py/nodes/lora_stacker.py index 41fed8f8..6cf2ef38 100644 --- a/py/nodes/lora_stacker.py +++ b/py/nodes/lora_stacker.py @@ -1,4 +1,3 @@ -from comfy.comfy_types import IO # type: ignore import os from ..utils.utils import get_lora_info from .utils import FlexibleOptionalInputType, any_type, extract_lora_name, get_loras_list @@ -15,7 +14,7 @@ class LoraStacker: def INPUT_TYPES(cls): return { "required": { - "text": (IO.STRING, { + "text": ("STRING", { "multiline": True, "pysssss.autocomplete": False, "dynamicPrompts": True, @@ -26,7 +25,7 @@ class LoraStacker: "optional": FlexibleOptionalInputType(any_type), } - RETURN_TYPES = ("LORA_STACK", IO.STRING, IO.STRING) + RETURN_TYPES = ("LORA_STACK", "STRING", "STRING") RETURN_NAMES = ("LORA_STACK", "trigger_words", "active_loras") FUNCTION = "stack_loras" diff --git a/py/nodes/prompt.py b/py/nodes/prompt.py index 220505c2..91c2409a 100644 --- a/py/nodes/prompt.py +++ b/py/nodes/prompt.py @@ -1,5 +1,4 @@ from typing import Any, Optional -from nodes import CLIPTextEncode # type: ignore class PromptLoraManager: """Encodes text (and optional trigger words) into CLIP conditioning.""" @@ -55,5 +54,6 @@ class PromptLoraManager: if trigger_words: prompt = ", ".join([trigger_words, text]) + from nodes import CLIPTextEncode # type: ignore conditioning = CLIPTextEncode().encode(clip, prompt)[0] return (conditioning, prompt,) \ No newline at end of file diff --git a/py/nodes/trigger_word_toggle.py b/py/nodes/trigger_word_toggle.py index 169522fc..ea0c1b2d 100644 --- a/py/nodes/trigger_word_toggle.py +++ b/py/nodes/trigger_word_toggle.py @@ -1,6 +1,5 @@ import json import re -from server import PromptServer # type: ignore from .utils import FlexibleOptionalInputType, any_type import logging diff --git a/py/nodes/wanvideo_lora_select.py b/py/nodes/wanvideo_lora_select.py index d948eb02..b93796f4 100644 --- a/py/nodes/wanvideo_lora_select.py +++ b/py/nodes/wanvideo_lora_select.py @@ -1,4 +1,3 @@ -from comfy.comfy_types import IO # type: ignore import folder_paths # type: ignore from ..utils.utils import get_lora_info from .utils import FlexibleOptionalInputType, any_type, get_loras_list @@ -16,7 +15,7 @@ class WanVideoLoraSelect: "required": { "low_mem_load": ("BOOLEAN", {"default": False, "tooltip": "Load LORA models with less VRAM usage, slower loading. This affects ALL LoRAs, not just the current ones. No effect if merge_loras is False"}), "merge_loras": ("BOOLEAN", {"default": True, "tooltip": "Merge LoRAs into the model, otherwise they are loaded on the fly. Always disabled for GGUF and scaled fp8 models. This affects ALL LoRAs, not just the current one"}), - "text": (IO.STRING, { + "text": ("STRING", { "multiline": True, "pysssss.autocomplete": False, "dynamicPrompts": True, @@ -27,7 +26,7 @@ class WanVideoLoraSelect: "optional": FlexibleOptionalInputType(any_type), } - RETURN_TYPES = ("WANVIDLORA", IO.STRING, IO.STRING) + RETURN_TYPES = ("WANVIDLORA", "STRING", "STRING") RETURN_NAMES = ("lora", "trigger_words", "active_loras") FUNCTION = "process_loras" diff --git a/py/nodes/wanvideo_lora_select_from_text.py b/py/nodes/wanvideo_lora_select_from_text.py index 1b1a4d43..96b307ff 100644 --- a/py/nodes/wanvideo_lora_select_from_text.py +++ b/py/nodes/wanvideo_lora_select_from_text.py @@ -1,5 +1,4 @@ -from comfy.comfy_types import IO -import folder_paths +import folder_paths # type: ignore from ..utils.utils import get_lora_info from .utils import any_type import logging @@ -20,7 +19,7 @@ class WanVideoLoraSelectFromText: "required": { "low_mem_load": ("BOOLEAN", {"default": False, "tooltip": "Load LORA models with less VRAM usage, slower loading. This affects ALL LoRAs, not just the current ones. No effect if merge_loras is False"}), "merge_lora": ("BOOLEAN", {"default": True, "tooltip": "Merge LoRAs into the model, otherwise they are loaded on the fly. Always disabled for GGUF and scaled fp8 models. This affects ALL LoRAs, not just the current one"}), - "lora_syntax": (IO.STRING, { + "lora_syntax": ("STRING", { "multiline": True, "defaultInput": True, "forceInput": True, @@ -34,7 +33,7 @@ class WanVideoLoraSelectFromText: } } - RETURN_TYPES = ("WANVIDLORA", IO.STRING, IO.STRING) + RETURN_TYPES = ("WANVIDLORA", "STRING", "STRING") RETURN_NAMES = ("lora", "trigger_words", "active_loras") FUNCTION = "process_loras_from_syntax"