code: def get_obj_module(qualname):
      
      modname = qualname
      classname = None
      attrname = None
      while modname not in sys.modules:
          attrname = classname
          modname, classname = modname.rsplit('.', 1)
  
      # retrieve object and find original module name
      if classname:
          cls = getattr(sys.modules[modname], classname)
          modname = cls.__module__
          obj = getattr(cls, attrname) if attrname else cls
      else:
          obj = None
  
      return obj, sys.modules[modname]
docs: Get a module/class/attribute and its original module by qualname