ComfyUI/comfy/component_model/make_mutable.py
doctorpangloss 1b2ea61345 Improved API support
- Run comfyui workflows directly inside other python applications using
   EmbeddedComfyClient.
 - Optional telemetry in prompts and models using anonymity preserving
   Plausible self-hosted or hosted.
 - Better OpenAPI schema
 - Basic support for distributed ComfyUI backends. Limitations: no
   progress reporting, no easy way to start your own distributed
   backend, requires RabbitMQ as a message broker.
2024-02-07 14:20:21 -08:00

21 lines
649 B
Python

from typing import Mapping, Any
def make_mutable(obj: Any) -> dict:
"""
Makes an immutable dict, frozenset or tuple mutable. Otherwise, returns the value.
:param obj: any object
:return:
"""
if isinstance(obj, Mapping) and not isinstance(obj, dict) and not hasattr(obj, "__setitem__"):
obj = dict(obj)
for key, value in obj.items():
obj[key] = make_mutable(value)
if isinstance(obj, tuple):
obj = list(obj)
for i in range(len(obj)):
obj[i] = make_mutable(obj[i])
if isinstance(obj, frozenset):
obj = set([make_mutable(x) for x in obj])
return obj