code: def superreload(module, reload=reload, old_objects=None, shell=None):
      """Enhanced version of the builtin reload function.
  
      superreload remembers objects previously in the module, and
  
      - upgrades the class dictionary of every old class in the module
      - upgrades the code object of every old function and method
      - clears the module's namespace before reloading
  
      """
      if old_objects is None:
          old_objects = {}
  
      # collect old objects in the module
      for name, obj in list(module.__dict__.items()):
          if not append_obj(module, old_objects, name, obj):
              continue
          key = (module.__name__, name)
          try:
              old_objects.setdefault(key, []).append(weakref.ref(obj))
          except TypeError:
              pass
  
      # reload module
      try:
          # clear namespace first from old cruft
          old_dict = module.__dict__.copy()
          old_name = module.__name__
          module.__dict__.clear()
          module.__dict__["__name__"] = old_name
          module.__dict__["__loader__"] = old_dict["__loader__"]
      except (TypeError, AttributeError, KeyError):
          pass
  
      try:
          module = reload(module)
      except:
          # restore module dictionary on failed reload
          module.__dict__.update(old_dict)
          raise
  
      # iterate over all objects and update functions & classes
      for name, new_obj in list(module.__dict__.items()):
          key = (module.__name__, name)
          if key not in old_objects:
              # here 'shell' acts both as a flag and as an output var
              if (
                  shell is None
                  or name == "Enum"
                  or not append_obj(
                      module, old_objects, name, new_obj, True
                  )
              ):
                  continue
              shell.user_ns[name] = new_obj
  
          new_refs = []
          for old_ref in old_objects[key]:
              old_obj = old_ref()
              if old_obj is None:
                  continue
              new_refs.append(old_ref)
              update_generic(old_obj, new_obj)
  
          if new_refs:
              old_objects[key] = new_refs
          else:
              del old_objects[key]
  
      return module
  
imports: from IPython.core import magic_arguments
  from IPython.core.magic import Magics, magics_class, line_magic
  import os
  import sys
  import traceback
  import types
  import weakref
  import gc
  import logging
  from importlib import import_module, reload
  from importlib.util import source_from_cache
label_desc: Use image node_id 8 for calling a global function with example usage: superreload(module, reload, old_objects, shell) and returns: module