code: def _transform_artifacts(
      artifacts: list[_TfxArtifact], type_hint: Any
  ) -> Any:
      """Transforms raw list[Artifact] to target type_hint with type checking."""
      if type_hint is None:
          return artifacts
  
      origin = get_origin(type_hint)
      args = get_args(type_hint)
      if origin and args:
          # List[T]
          if (
              origin in (list, Sequence, MutableSequence)
              and len(args) == 1
              and _is_valid_artifact_type(args[0])
          ):
              return _deserialize_artifact(args[0], artifacts)
  
      # Optional[T]
      is_opt, artifact_type = pure_typing_utils.maybe_unwrap_optional(
          type_hint
      )
      if is_opt and _is_valid_artifact_type(artifact_type):
          artifacts = _deserialize_artifact(artifact_type, artifacts)
          if not artifacts:
              return None
          elif len(artifacts) == 1:
              return artifacts[0]
          else:
              raise errors.InvalidTypeHintError(
                  f"type_hint = {type_hint} but got {len(artifacts)} artifacts. Please"
                  f" use list[{artifact_type.__name__}] annotation instead."
              )
  
      # Just T
      if _is_valid_artifact_type(artifact_type):
          artifacts = _deserialize_artifact(artifact_type, artifacts)
          if len(artifacts) == 1:
              return artifacts[0]
          else:
              raise errors.InvalidTypeHintError(
                  f"type_hint = {type_hint} but got {len(artifacts)} artifacts. Please"
                  f" use list[{artifact_type.__name__}] or"
                  f" Optional[{artifact_type.__name__}] annotation instead."
              )
  
      raise errors.InvalidTypeHintError(
          f"Unsupported annotation: {type_hint}"
      )
  
file_path: tfx/tfx/orchestration/portable/execution/di_providers.py
imports: from collections.abc import Container, MutableSequence, Sequence
  import inspect
  from typing import Any, Callable, TypeVar, get_args, get_origin
  from tfx.orchestration.portable import data_types
  from tfx.types import artifact
  from tfx.utils import pure_typing_utils
  from tfx.utils.di import errors
  from tfx.utils.di import providers
label_desc: Use image node_id 4 for calling a global function with example usage: _transform_artifacts(artifacts, type_hint) and returns: artifacts, _deserialize_artifact, None, artifacts, artifacts