def update(self, in_place: bool = True, **changes) -> Any:  # noqa: ANN401
        """Replace fields in place and call __post_init__ to reinitialize.

        Args:
            in_place: Whether to modify in place or return new instance
            **changes: Field names and new values to update

        Returns:
            Updated instance (self if in_place=True, new instance otherwise)

        Raises:
            TypeError: If instance is not a dataclass
        """
        if not is_dataclass(self):
            msg = "replace can only be used with dataclass instances"
            raise TypeError(msg)

        if in_place:
            for field in fields(self):
                if field.init and field.name in changes:
                    setattr(self, field.name, changes[field.name])
            if hasattr(self, "__post_init__"):
                self.__post_init__()
            return self
        return replace(self, **changes)
Replace fields in place and call __post_init__ to reinitialize.

        Args:
            in_place: Whether to modify in place or return new instance
            **changes: Field names and new values to update

        Returns:
            Updated instance (self if in_place=True, new instance otherwise)

        Raises:
            TypeError: If instance is not a dataclass
        
src/anomalib/data/dataclasses/generic.py