code: def check_mapping(name: str, mapping: Optional[T]) -> T:
      """Cleans inputs to apply_fn, providing better errors."""
      if mapping is None:
          # Convert None to empty dict.
          mapping = dict()
      if not isinstance(mapping, Mapping):
          if type(mapping).__name__ == "_DictWrapper":
              # TensorFlow's checkpointing infrastructure replaces `dict` instances on
              # `tf.Module`s with a type that is not a `Mapping` instance.
              return mapping
  
          raise TypeError(
              f"{name} argument does not appear valid. It should be a "
              f"mapping but is of type {type(mapping)}. "
              "For reference the parameters for apply are "
              "`apply(params, rng, ...)`` for `hk.transform` and "
              "`apply(params, state, rng, ...)` for "
              "`hk.transform_with_state`.\n"
              f"The argument was: {mapping!r}."
          )
      return mapping
  
imports: from collections.abc import Mapping
  import inspect
  from typing import Any, Callable, NamedTuple, Optional, TypeVar, Union
  from haiku._src import analytics
  from haiku._src import base
  from haiku._src import data_structures
  from haiku._src import typing
  import jax
label_desc: Use image node_id 12 for calling a global function with example usage: check_mapping(name, mapping) and returns: mapping, mapping