code: def _format_replace(
      replace: Optional[ReplaceTypes] = None,
  ) -> dict[Variable, Variable]:
      items: dict[Variable, Variable]
      if isinstance(replace, dict):
          # PyLance has issues with type resolution
          items = cast(dict[Variable, Variable], replace)
      elif isinstance(replace, Iterable):
          items = dict(replace)
      elif replace is None:
          items = {}
      else:
          raise ValueError(
              "replace is neither a dictionary, list, "
              f"tuple or None ! The value provided is {replace},"
              f"of type {type(replace)}"
          )
      return items
  
imports: import warnings
  from collections.abc import Iterable, Mapping, Sequence
  from functools import partial, singledispatch
  from typing import Optional, Union, cast, overload
  from pytensor.graph.basic import Apply, Constant, Variable, io_toposort, truncated_graph_inputs
  from pytensor.graph.fg import FunctionGraph
  from pytensor.graph.op import Op
label_desc: Use image node_id 1 for calling a global function with example usage: _format_replace(replace) and returns: items