From a59ea00074946a575ab90d64d5a0e7d42676cd64 Mon Sep 17 00:00:00 2001 From: "Lex Darlog (DRL)" <3897975+Lex-DRL@users.noreply.github.com> Date: Tue, 14 Apr 2026 06:55:29 -0300 Subject: [PATCH] `ValidateKeys` --- node_validate.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 node_validate.py diff --git a/node_validate.py b/node_validate.py new file mode 100644 index 0000000..ce3a333 --- /dev/null +++ b/node_validate.py @@ -0,0 +1,58 @@ +# encoding: utf-8 +"""Code for the dict-validator node.""" + +from inspect import cleandoc as _cleandoc + +from comfy_api.latest import io as _io + +from .__meta import ( + category_dict as _category_dict, + pack_id_suffix as _pack_id +) +from .__typing import _A, _U, _O, _t, T as _T, FormatDict as _FormatDict +from ._dict import _verify_input_dict +from ._io_custom import ( + _BaseNode, + _DICT_INPUT_OPTIONAL, _DICT_OUTPUT, + _schema_old_name +) +from .docstring_formatter import format_docstring as _format_docstring + +# ---------------------------------------------------------- + +class ValidateKeys(_BaseNode): + """ + Verify the dict to have string-formatting-compatible keys. No need to add it before "String Formatter" node, + but it might be handy to verify the dict in the very beginning of the graph - right after the keys are set. + """ + _schema = _io.Schema( + node_id=f'ValidateKeys{_pack_id}', + display_name='Validate Dict', + category=_category_dict, + description=_format_docstring(_cleandoc(__doc__)), + inputs=[_DICT_INPUT_OPTIONAL], + outputs=[_DICT_OUTPUT], + # hidden=[_io.Hidden.unique_id], + is_output_node=True, + ) + + @classmethod + def execute(cls, dict: _O[_FormatDict] = None) -> _io.NodeOutput: + # try: + # _verify_input_dict(dict, error_if_none=True) + # except Exception: + # _show_text_on_node('❌', unique_id) + # raise + # return (Null, ) + # _show_text_on_node('✅', unique_id) + _verify_input_dict(dict, error_if_none=True) + return _io.NodeOutput(dict) + +# ========================================================== +# Deprecated node with old ID (for backwards compatibility) + +class ValidateKeysOld1(ValidateKeys): + _schema = _schema_old_name( + ValidateKeys._schema, + 'StringConstructorValidateKeys' + )