code: def update_class(old, new):
      """Replace stuff in the __dict__ of a class, and upgrade
      method code objects, and add new methods, if any"""
      for key in list(old.__dict__.keys()):
          old_obj = getattr(old, key)
          try:
              new_obj = getattr(new, key)
              # explicitly checking that comparison returns True to handle
              # cases where `==` doesn't return a boolean.
              if (old_obj == new_obj) is True:
                  continue
          except AttributeError:
              # obsolete attribute: remove it
              try:
                  delattr(old, key)
              except (AttributeError, TypeError):
                  pass
              continue
          except ValueError:
              # can't compare nested structures containing
              # numpy arrays using `==`
              pass
  
          if update_generic(old_obj, new_obj):
              continue
  
          try:
              setattr(old, key, getattr(new, key))
          except (AttributeError, TypeError):
              pass  # skip non-writable attributes
  
      for key in list(new.__dict__.keys()):
          if key not in list(old.__dict__.keys()):
              try:
                  setattr(old, key, getattr(new, key))
              except (AttributeError, TypeError):
                  pass  # skip non-writable attributes
  
      # update all instances of class
      update_instances(old, new)
  
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 3 for calling a global function with example usage: update_class(old, new) without return types