code: def search_class_module(cls, deep_search=True):
      
      for md_name in sys.modules:
          module = sys.modules[md_name]
          if hasattr(module, cls.__name__) and getattr(module, cls.__name__) is cls:
              return module
      if deep_search:
          for md_name in sys.modules:
              module = sys.modules[md_name]
              try:
                  nst = _get_class_nesting_list(cls, module)
                  if cls is nst[-1]:
                      return module
              except:
                  pass
      return None
docs: E.g. if cls is a TypeVar, cls.__module__ won't contain the actual module
      that declares cls. This returns the actual module declaring cls.
      Can be used with any class (not only TypeVar), though usually cls.__module__
      is the recommended way.
      If deep_search is True (default) this even finds the correct module if it
      declares cls as an inner class of another class.