class_docstr: Represents the TraceType of a class implmenting the CustomNestProtocol.
class_docstr_tok: ["Represents","the","TraceType","of","a","class","implmenting","the","CustomNestProtocol","."]
code: def cast(self, value: Any, casting_context: Any) -> Any:
      if not isinstance(value, self.value_type):
          raise TypeError(
              f"[{value!r}] is not of type {self.value_type}."
          )
      value_metadata, value_components = value.__tf_flatten__()
      if self.metadata != value_metadata:
          raise ValueError(
              f"Metadata mismatch: [{self.metadata!r}] != [{value_metadata!r}]."
          )
      if len(self.components) != len(value_components):
          raise ValueError(
              f"Lengths of components mismatch: {len(self.components)} != "
              f"{len(value_components)}."
          )
  
      (
          casted_value_components,
          was_casted,
      ) = util.cast_and_return_whether_casted(
          self.components, value_components, casting_context
      )
      if was_casted:
          return self.value_type.__tf_unflatten__(
              self.metadata, casted_value_components
          )
      else:
          return value
  
file_path: tensorflow/tensorflow/core/function/trace_type/custom_nest_trace_type.py
imports: from typing import Any, Iterator, List, Optional, Sequence, Tuple, Type
  from tensorflow.core.function.trace_type import util
  from tensorflow.python.types import trace
  from tensorflow.python.util import custom_nest_protocol
label_desc: Use image node_id 11 for calling the CustomNestTraceType obj's underlying member method code with example usage: obj.cast(value, casting_context) and returns: self, value