code: def superreload(module, reload=reload, old_objects={}):
      """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
  
      """
  
      # collect old objects in the module
      for name, obj in list(module.__dict__.items()):
          if (
              not hasattr(obj, "__module__")
              or obj.__module__ != module.__name__
          ):
              continue
          key = (module.__name__, name)
          try:
              old_objects.setdefault(key, []).append(weakref.ref(obj))
          except TypeError:
              # weakref doesn't work for all types;
              # create strong references for 'important' cases
              if not PY3 and isinstance(obj, types.ClassType):
                  old_objects.setdefault(key, []).append(StrongRef(obj))
  
      # 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:
              continue
  
          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 __future__ import print_function
  import os
  import sys
  import traceback
  import types
  import weakref
  from IPython.utils import openpy
  from IPython.utils.py3compat import PY3
  from IPython.core.magic import Magics, magics_class, line_magic
label_desc: Use image node_id 6 for calling a global function with example usage: superreload(module, reload, old_objects) and returns: module