mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-12-17 01:52:59 +08:00
Fixed providing list of allowed_types
This commit is contained in:
parent
4057540efe
commit
e31f7a1128
@ -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):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user