code: def _find_package(parts):
      
      for i in range(len(parts), 0, -1):
          prefix = '.'.join(parts[0:i])
          if prefix in sys.modules:
              return i, sys.modules[prefix]
      return 0, None
docs: Helper function for _resolve_import_versioned.