code: def load_module(
      filename: Union[str, os.PathLike] = None,
      module: Optional[Union[ModuleType, str]] = None,
      **kwds,
  ) -> Optional[ModuleType]:
      """Update the selected module (default is :py:mod:`__main__`) with
      the state saved at ``filename``.
  
      Restore a module to the state saved with :py:func:`dump_module`. The
      saved module can be :py:mod:`__main__` (e.g. an interpreter session),
      an imported module, or a module-type object (e.g. created with
      :py:class:`~types.ModuleType`).
  
      When restoring the state of a non-importable module-type object, the
      current instance of this module may be passed as the argument ``main``.
      Otherwise, a new instance is created with :py:class:`~types.ModuleType`
      and returned.
  
      Args:
          filename: a path-like object or a readable stream. If `None`
              (the default), read from a named file in a temporary directory.
          module: a module object or the name of an importable module;
              the module name and kind (i.e. imported or non-imported) must
              match the name and kind of the module stored at ``filename``.
          **kwds: extra keyword arguments passed to :py:class:`Unpickler()`.
  
      Raises:
          :py:exc:`UnpicklingError`: if unpickling fails.
          :py:exc:`ValueError`: if the argument ``main`` and module saved
              at ``filename`` are incompatible.
  
      Returns:
          A module object, if the saved module is not :py:mod:`__main__` or
          a module instance wasn't provided with the argument ``main``.
  
      Examples:
  
          - Save the state of some modules:
  
            >>> import dill
            >>> squared = lambda x: x*x
            >>> dill.dump_module() # save state of __main__ to /tmp/session.pkl
            >>>
            >>> import pox # an imported module
            >>> pox.plus_one = lambda x: x+1
            >>> dill.dump_module('pox_session.pkl', module=pox)
            >>>
            >>> from types import ModuleType
            >>> foo = ModuleType('foo') # a module-type object
            >>> foo.values = [1,2,3]
            >>> import math
            >>> foo.sin = math.sin
            >>> dill.dump_module('foo_session.pkl', module=foo, refimported=True)
  
          - Restore the state of the interpreter:
  
            >>> import dill
            >>> dill.load_module() # updates __main__ from /tmp/session.pkl
            >>> squared(2)
            4
  
          - Load the saved state of an importable module:
  
            >>> import dill
            >>> pox = dill.load_module('pox_session.pkl')
            >>> pox.plus_one(1)
            2
            >>> import sys
            >>> pox in sys.modules.values()
            True
  
          - Load the saved state of a non-importable module-type object:
  
            >>> import dill
            >>> foo = dill.load_module('foo_session.pkl')
            >>> [foo.sin(x) for x in foo.values]
            [0.8414709848078965, 0.9092974268256817, 0.1411200080598672]
            >>> import math
            >>> foo.sin is math.sin # foo.sin was saved by reference
            True
            >>> import sys
            >>> foo in sys.modules.values()
            False
  
          - Update the state of a non-importable module-type object:
  
            >>> import dill
            >>> from types import ModuleType
            >>> foo = ModuleType('foo')
            >>> foo.values = ['a','b']
            >>> foo.sin = lambda x: x*x
            >>> dill.load_module('foo_session.pkl', module=foo)
            >>> [foo.sin(x) for x in foo.values]
            [0.8414709848078965, 0.9092974268256817, 0.1411200080598672]
  
      *Changed in version 0.3.6:* Function ``load_session()`` was renamed to
      ``load_module()``. Parameter ``main`` was renamed to ``module``.
  
      See also:
          :py:func:`load_module_asdict` to load the contents of module saved
          with :py:func:`dump_module` into a dictionary.
      """
      if "main" in kwds:
          warnings.warn(
              "The argument 'main' has been renamed 'module'.",
              PendingDeprecationWarning,
          )
          if module is not None:
              raise TypeError(
                  "both 'module' and 'main' arguments were used"
              )
          module = kwds.pop("main")
      main = module
      if hasattr(filename, "read"):
          file = filename
      else:
          if filename is None:
              filename = str(TEMPDIR / "session.pkl")
          file = open(filename, "rb")
      try:
          file = _make_peekable(file)
          # FIXME: dill.settings are disabled
          unpickler = Unpickler(file, **kwds)
          unpickler._session = True
  
          # Resolve unpickler._main
          pickle_main = _identify_module(file, main)
          if main is None and pickle_main is not None:
              main = pickle_main
          if isinstance(main, str):
              if main.startswith("__runtime__."):
                  # Create runtime module to load the session into.
                  main = ModuleType(main.partition(".")[-1])
              else:
                  main = _import_module(main)
          if main is not None:
              if not isinstance(main, ModuleType):
                  raise TypeError("%r is not a module" % main)
              unpickler._main = main
          else:
              main = unpickler._main
  
          # Check against the pickle's main.
          is_main_imported = _is_imported_module(main)
          if pickle_main is not None:
              is_runtime_mod = pickle_main.startswith("__runtime__.")
              if is_runtime_mod:
                  pickle_main = pickle_main.partition(".")[-1]
              error_msg = "can't update{} module{} %r with the saved state of{} module{} %r"
              if is_runtime_mod and is_main_imported:
                  raise ValueError(
                      error_msg.format(
                          " imported", "", "", "-type object"
                      )
                      % (main.__name__, pickle_main)
                  )
              if not is_runtime_mod and not is_main_imported:
                  raise ValueError(
                      error_msg.format(
                          "", "-type object", " imported", ""
                      )
                      % (pickle_main, main.__name__)
                  )
              if main.__name__ != pickle_main:
                  raise ValueError(
                      error_msg.format("", "", "", "")
                      % (main.__name__, pickle_main)
                  )
  
          # This is for find_class() to be able to locate it.
          if not is_main_imported:
              runtime_main = "__runtime__.%s" % main.__name__
              sys.modules[runtime_main] = main
  
          loaded = unpickler.load()
      finally:
          if not hasattr(filename, "read"):  # if newly opened file
              file.close()
          try:
              del sys.modules[runtime_main]
          except (KeyError, NameError):
              pass
      assert loaded is main
      _restore_modules(unpickler, main)
      if main is _main_module or main is module:
          return None
      else:
          return main
  
imports: import re
  import os
  import sys
  import warnings
  from dill import _dill, Pickler, Unpickler
  from ._dill import BuiltinMethodType, FunctionType, MethodType, ModuleType, TypeType, _import_module, _is_builtin_module, _is_imported_module, _main_module, _reverse_typemap, __builtin__
  from typing import Optional, Union
  import pathlib
  import tempfile
label_desc: Use image node_id 9 for calling a global function with example usage: load_module(filename, module) and returns: None, main