MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / __post_init__

Method __post_init__

diffusers/src/diffusers/utils/outputs.py:76–93  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

74 )
75
76 def __post_init__(self) -> None:
77 class_fields = fields(self)
78
79 # Safety and consistency checks
80 if not len(class_fields):
81 raise ValueError(f"{self.__class__.__name__} has no fields.")
82
83 first_field = getattr(self, class_fields[0].name)
84 other_fields_are_none = all(getattr(self, field.name) is None for field in class_fields[1:])
85
86 if other_fields_are_none and isinstance(first_field, dict):
87 for key, value in first_field.items():
88 self[key] = value
89 else:
90 for field in class_fields:
91 v = getattr(self, field.name)
92 if v is not None:
93 self[field.name] = v
94
95 def __delitem__(self, *args, **kwargs):
96 raise Exception(f"You cannot use ``__delitem__`` on a {self.__class__.__name__} instance.")

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected