code: def with_overrides(
      original: T, overrides_dict: Dict[str, Any], prefix: str = ""
  ) -> T:
      merged: T
      keys: Union[Iterable[str], Iterable[int]]
      if isinstance(original, list):
          merged = [None] * len(original)
          keys = range(len(original))
      elif isinstance(original, dict):
          merged = {}
          keys = chain(
              original.keys(),
              (
                  k
                  for k in overrides_dict
                  if "." not in k and k not in original
              ),
          )
      else:
          if prefix:
              raise ValueError(
                  f"overrides for '{prefix[:-1]}.*' expected list or dict in original, "
                  f"found {type(original)} instead"
              )
          else:
              raise ValueError(
                  f"expected list or dict, found {type(original)} instead"
              )
  
      used_override_keys: Set[str] = set()
      for key in keys:
          if str(key) in overrides_dict:
              merged[key] = copy.deepcopy(overrides_dict[str(key)])
              used_override_keys.add(str(key))
          else:
              overrides_subdict = {}
              for o_key in overrides_dict:
                  if o_key.startswith(f"{key}."):
                      overrides_subdict[
                          o_key[len(f"{key}.") :]
                      ] = overrides_dict[o_key]
                      used_override_keys.add(o_key)
              if overrides_subdict:
                  merged[key] = with_overrides(
                      original[key],
                      overrides_subdict,
                      prefix=prefix + f"{key}.",
                  )
              else:
                  merged[key] = copy.deepcopy(original[key])
  
      unused_override_keys = [
          prefix + key
          for key in set(overrides_dict.keys()) - used_override_keys
      ]
      if unused_override_keys:
          raise ValueError(
              f"overrides dict contains unused keys: {unused_override_keys}"
          )
  
      return merged
  
imports: import copy
  from itertools import chain
  import json
  import logging
  import os
  import zlib
  from collections import OrderedDict
  from collections.abc import MutableMapping
  from os import PathLike
  from typing import Any, Dict, List, Union, Optional, TypeVar, Iterable, Set
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.file_utils import cached_path
label_desc: Use image node_id 4 for calling a global function with example usage: with_overrides(original, overrides_dict, prefix) and returns: merged