code: def rename_fields(
      d: dict[str, t.Any],
      current: str,
      replace_with: str | None = None,
      *,
      remove_only: bool = False,
  ):
      # We assume that the given dictionary is already flattened.
      # This function will rename the keys in the dictionary.
      # If `replace_with` is None, then the key will be removed.
      if depth(d) != 1:
          raise ValueError(
              "Given dictionary is not flattened. Use flatten_dict first."
          ) from None
      if current in d:
          if remove_only:
              logger.warning(
                  "Field '%s' is deprecated and will be removed."
                  % current
              )
              d.pop(current)
          else:
              assert replace_with, "'replace_with' must be provided."
              logger.warning(
                  "Field '%s' is deprecated and has been renamed to '%s'"
                  % (current, replace_with)
              )
              d[replace_with] = d.pop(current)
  
imports: from __future__ import annotations
  import ipaddress
  import logging
  import os
  import re
  import typing
  from functools import singledispatch
  from typing import TYPE_CHECKING
  import schema
  import yaml
  from ...exceptions import BentoMLConfigException
  from ..utils import LazyLoader
label_desc: Use image node_id 4 for calling a global function with example usage: rename_fields(d, current, replace_with) without return types