Fixed providing list of allowed_types

This commit is contained in:
Jedrzej Kosinski 2025-11-04 16:06:26 -08:00
parent 4057540efe
commit e31f7a1128

View File

@ -4,6 +4,7 @@ import copy
import inspect import inspect
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from collections import Counter from collections import Counter
from collections.abc import Iterable
from dataclasses import asdict, dataclass from dataclasses import asdict, dataclass
from enum import Enum from enum import Enum
from typing import Any, Callable, Literal, TypedDict, TypeVar, TYPE_CHECKING from typing import Any, Callable, Literal, TypedDict, TypeVar, TYPE_CHECKING
@ -882,12 +883,22 @@ class MatchType(ComfyTypeIO):
class Template: class Template:
def __init__(self, template_id: str, allowed_types: _ComfyType | list[_ComfyType] = AnyType): def __init__(self, template_id: str, allowed_types: _ComfyType | list[_ComfyType] = AnyType):
self.template_id = template_id self.template_id = template_id
self.allowed_types = [allowed_types] if issubclass(allowed_types, _ComfyType) else allowed_types # account for syntactic sugar
if not isinstance(allowed_types, Iterable):
allowed_types = [allowed_types]
for t in allowed_types:
if not isinstance(t, type):
if not isinstance(t, _ComfyType):
raise ValueError(f"Allowed types must be a ComfyType or a list of ComfyTypes, got {t.__class__.__name__}")
else:
if not issubclass(t, _ComfyType):
raise ValueError(f"Allowed types must be a ComfyType or a list of ComfyTypes, got {t.__name__}")
self.allowed_types = allowed_types
def as_dict(self): def as_dict(self):
return { return {
"template_id": self.template_id, "template_id": self.template_id,
"allowed_types": "".join(t.io_type for t in self.allowed_types), "allowed_types": ",".join([t.io_type for t in self.allowed_types]),
} }
class Input(DynamicInput): class Input(DynamicInput):