code: def upgrade(nb, from_version=2, from_minor=0):
      """Convert a notebook to v3.
  
      Parameters
      ----------
      nb : NotebookNode
          The Python representation of the notebook to convert.
      from_version : int
          The original version of the notebook to convert.
      from_minor : int
          The original minor version of the notebook to convert (only relevant for v >= 3).
      """
      if from_version == 2:
          # Mark the original nbformat so consumers know it has been converted.
          nb.nbformat = nbformat
          nb.nbformat_minor = nbformat_minor
  
          nb.orig_nbformat = 2
          nb = _unbytes(nb)
          for ws in nb["worksheets"]:
              for cell in ws["cells"]:
                  cell.setdefault("metadata", {})
          return nb
      if from_version == 3:
          if from_minor != nbformat_minor:
              nb.orig_nbformat_minor = from_minor
          nb.nbformat_minor = nbformat_minor
          return nb
      msg = (
          "Cannot convert a notebook directly from v%s to v3.  "
          "Try using the nbformat.convert module." % from_version
      )
      raise ValueError(msg)
  
imports: from __future__ import annotations
  from .nbbase import nbformat, nbformat_minor
label_desc: Use image node_id 2 for calling a global function with example usage: upgrade(nb, from_version, from_minor) and returns: nb, nb