How do I migrate from imp?

So, based on importlib documentation I figured I might be able to replace imp.find_module + imp.load_module with:

spec = importlib.machinery.PathFinder.find_spec(modname, [""])
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
sys.modules[modname] = mod

However, I still don’t know if this:

  1. is actually correct
  2. is the one obvious way to do it

(Full patch available in Fedora or upstream.)