class_docstr: A placeholder that evaluates to a proto message.
class_docstr_tok: ["A","placeholder","that","evaluates","to","a","proto","message","."]
docstr: Validates the given value and transforms it to what encode() needs.
docstr_tok: ["Validates","the","given","value","and","transforms","it","to","what","encode","(",")","needs","."]
code: def _validate_and_transform_field(
      self, field: str, value: _InputFieldValues
  ) -> Optional[_FieldValues]:
      """Validates the given value and transforms it to what encode() needs."""
      message_name = self._base_message.DESCRIPTOR.full_name
      if field not in self._base_message.DESCRIPTOR.fields_by_name:
          raise ValueError(
              f"Unknown field {field} for proto {message_name}."
          )
      descriptor: descriptor_lib.FieldDescriptor = (
          self._base_message.DESCRIPTOR.fields_by_name[field]
      )
      field_name = f"{message_name}.{descriptor.name}"
  
      if (  # If it's a map<> field.
          descriptor.message_type
          and descriptor.message_type.has_options
          and descriptor.message_type.GetOptions().map_entry
      ):
          if value is None:
              return None
          if isinstance(value, dict):
              value = value.items()
          elif not isinstance(value, list):
              raise ValueError(
                  "Expected dict[k,v] or list[tuple[k, v]] input for map field "
                  f"{field_name}, got {value!r}."
              )
          entries: List[
              Tuple[
                  Union[str, placeholder_base.Placeholder], _PlainValues
              ]
          ] = []
          for entry_key, entry_value in value:
              if not isinstance(
                  entry_key, (str, placeholder_base.Placeholder)
              ) or isinstance(
                  entry_key,
                  (
                      MakeProtoPlaceholder,
                      placeholder_base.ListPlaceholder,
                      placeholder_base.DictPlaceholder,
                  ),
              ):
                  raise ValueError(
                      "Expected string (placeholder) for dict key of map field "
                      f"{field_name}, got {entry_key!r}."
                  )
              value_descriptor = descriptor.message_type.fields_by_name[
                  "value"
              ]
              entry_value = self._validate_and_transform_value(
                  f"{field_name}.value", value_descriptor, entry_value
              )
              if entry_value is not None:
                  entries.append((entry_key, entry_value))
          return placeholder_base.make_dict(entries)
      elif (
          descriptor.label
          == descriptor_lib.FieldDescriptor.LABEL_REPEATED
      ):
          if value is None or isinstance(
              value, placeholder_base.Placeholder
          ):
              return value  # pytype: disable=bad-return-type
          if not isinstance(value, list):
              raise ValueError(
                  f"Expected list input for repeated field {field_name}, got "
                  f"{value!r}."
              )
          items: List[_PlainValues] = []
          for item in value:
              item = self._validate_and_transform_value(
                  field_name, descriptor, item
              )
              if item is not None:
                  items.append(item)
          return placeholder_base.make_list(items)
      else:
          return self._validate_and_transform_value(
              field_name, descriptor, value
          )
  
file_path: tfx/tfx/dsl/placeholder/proto_placeholder.py
imports: from __future__ import annotations
  from typing import Dict, Generic, Iterator, List, Optional, Tuple, Type, TypeVar, Union
  from tfx.dsl.placeholder import placeholder_base
  from tfx.proto.orchestration import placeholder_pb2
  from tfx.utils import proto_utils
  from google.protobuf import any_pb2
  from google.protobuf import descriptor
  from google.protobuf import message
label_desc: Use image node_id 2 for calling the MakeProtoPlaceholder obj's underlying member method code with example usage: obj._validate_and_transform_field(field, value) and returns: placeholder_base, None, placeholder_base, self, value