From a8a1e11284cf2db6fc9dbe384756ed3eee2cc579 Mon Sep 17 00:00:00 2001 From: "Aaron C. de Bruyn" Date: Tue, 10 Sep 2024 12:59:22 -0700 Subject: [PATCH] Add DarkAnyToString because mtb Any to String is broken --- __init__.py | 3 +++ modules/convert.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 modules/convert.py diff --git a/__init__.py b/__init__.py index ae01753..63e0390 100644 --- a/__init__.py +++ b/__init__.py @@ -8,6 +8,7 @@ from .modules import faces from .modules import prompts from .modules import files from .modules import checkpoints +from .modules import convert logger = logging.getLogger(__name__) @@ -21,6 +22,7 @@ NODE_CLASS_MAPPINGS = { "DarkFaceIndexGenerator": faces.DarkFaceIndexGenerator, "DarkCheckpointRandomizer": checkpoints.DarkCheckpointRandomizer, "DarkCheckpointSwitcher": checkpoints.DarkCheckpointSwitcher, + "DarkAnyToString": convert.DarkAnyToString, } NODE_DISPLAY_NAME_MAPPINGS = { @@ -32,6 +34,7 @@ NODE_DISPLAY_NAME_MAPPINGS = { "DarkFaceIndexGenerator": "Dark Face Index Generator", "DarkCheckpointRandomizer": "Dark Checkpoint Randomizer", "DarkCheckpointSwitcher": "Dark Checkpoint Switcher", + "DarkAnyToString": "Dark Any to String", } __all__ = [NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS] diff --git a/modules/convert.py b/modules/convert.py new file mode 100644 index 0000000..00396e7 --- /dev/null +++ b/modules/convert.py @@ -0,0 +1,46 @@ +__version__ = "0.0.7" + + +import logging +from .utils.darkdata import DarkFolderBase + +logger = logging.getLogger(__name__) + + +# AnyType trick taken from here: https://github.com/comfyanonymous/ComfyUI/discussions/4830 +class AnyType(str): + def __ne__(self, __value: object) -> bool: + return False + + +any_typ = AnyType("*") + + +class DarkAnyToString(object): + """ + Convert anything to a string + """ + + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "anything": ( + any_typ, + { + "forceInput": True, + }, + ), + }, + } + + RETURN_TYPES = ("STRING",) + FUNCTION = "any_to_string" + + CATEGORY = "DarkPrompt" + + def any_to_string(self, anything): + return (str(anything),)