code: def _assign_returned_values(
      function,
      outputs: Dict[str, Any],
      returned_values: Dict[str, Any],
      output_dict: Dict[str, List[tfx_types.Artifact]],
      json_typehints: Dict[str, Type],  # pylint: disable=g-bare-generic
  ) -> Dict[str, List[tfx_types.Artifact]]:
      """Validates and assigns the outputs to the output_dict."""
      result = copy.deepcopy(output_dict)
      if not isinstance(outputs, dict):
          raise ValueError(
              (
                  "Expected component executor function %s to return a dict of "
                  "outputs (got %r instead)."
              )
              % (function, outputs)
          )
  
      # Assign returned ValueArtifact values.
      for name, is_optional in returned_values.items():
          if name not in outputs:
              raise ValueError(
                  "Did not receive expected output %r as return value from "
                  "component executor function %s." % (name, function)
              )
          if not is_optional and outputs[name] is None:
              raise ValueError(
                  "Non-nullable output %r received None return value from "
                  "component executor function %s." % (name, function)
              )
          try:
              result[name][0].value = outputs[name]
          except TypeError as e:
              raise TypeError(
                  (
                      "Return value %r for output %r is incompatible with output type "
                      "%r."
                  )
                  % (outputs[name], name, result[name][0].__class__)
              ) from e
          # Handle JsonValue runtime type check.
          if name in json_typehints:
              ret = json_compat.check_strict_json_compat(
                  outputs[name], json_typehints[name]
              )
              if not ret:
                  raise TypeError(
                      (
                          "Return value %r for output %r is incompatible with output type "
                          "%r."
                      )
                      % (outputs[name], name, json_typehints[name])
                  )
      return result
  
imports: import copy
  import functools
  import types
  import typing
  from typing import Any, Callable, ClassVar, Dict, List, Optional, Protocol, Type, Union
  from tfx import types
  from tfx.dsl.component.experimental import function_parser
  from tfx.dsl.component.experimental import json_compat
  from tfx.dsl.component.experimental import utils
  from tfx.dsl.components.base import base_beam_component
  from tfx.dsl.components.base import base_beam_executor
  from tfx.dsl.components.base import base_component
  from tfx.dsl.components.base import base_executor
  from tfx.dsl.components.base import executor_spec
  from tfx.types import channel
  from tfx.types import system_executions
label_desc: Use image node_id 2 for calling a global function with example usage: _assign_returned_values(function, outputs, returned_values, output_dict, json_typehints) and returns: result