code: def update(
      old: dict,
      new: Mapping,
      priority: Literal["old", "new", "new-defaults"] = "new",
      defaults: Mapping | None = None,
  ) -> dict:
      """Update a nested dictionary with values from another
  
      This is like dict.update except that it smoothly merges nested values
  
      This operates in-place and modifies old
  
      Parameters
      ----------
      priority: string {'old', 'new', 'new-defaults'}
          If new (default) then the new dictionary has preference.
          Otherwise the old dictionary does.
          If 'new-defaults', a mapping should be given of the current defaults.
          Only if a value in ``old`` matches the current default, it will be
          updated with ``new``.
  
      Examples
      --------
      >>> a = {'x': 1, 'y': {'a': 2}}
      >>> b = {'x': 2, 'y': {'b': 3}}
      >>> update(a, b)  # doctest: +SKIP
      {'x': 2, 'y': {'a': 2, 'b': 3}}
  
      >>> a = {'x': 1, 'y': {'a': 2}}
      >>> b = {'x': 2, 'y': {'b': 3}}
      >>> update(a, b, priority='old')  # doctest: +SKIP
      {'x': 1, 'y': {'a': 2, 'b': 3}}
  
      >>> d = {'x': 0, 'y': {'a': 2}}
      >>> a = {'x': 1, 'y': {'a': 2}}
      >>> b = {'x': 2, 'y': {'a': 3, 'b': 3}}
      >>> update(a, b, priority='new-defaults', defaults=d)  # doctest: +SKIP
      {'x': 1, 'y': {'a': 3, 'b': 3}}
  
      See Also
      --------
      dask.config.merge
      """
      for k, v in new.items():
          k = canonical_name(k, old)
  
          if isinstance(v, Mapping):
              if (
                  k not in old
                  or old[k] is None
                  or not isinstance(old[k], dict)
              ):
                  old[k] = {}
              update(
                  old[k],
                  v,
                  priority=priority,
                  defaults=defaults.get(k) if defaults else None,
              )
          else:
              if (
                  priority == "new"
                  or k not in old
                  or (
                      priority == "new-defaults"
                      and defaults
                      and k in defaults
                      and defaults[k] == old[k]
                  )
              ):
                  old[k] = v
  
      return old
  
imports: from __future__ import annotations
  import ast
  import base64
  import builtins
  import json
  import os
  import site
  import sys
  import threading
  import warnings
  from collections.abc import Mapping, Sequence
  from typing import Any, Literal
  import yaml
  from dask.typing import no_default
label_desc: Use image node_id 3 for calling a global function with example usage: update(old, new, priority, defaults) and returns: old