@@ -470,29 +470,22 @@ def get_loader(module_or_name):
470470def find_loader (fullname ):
471471 """Find a PEP 302 "loader" object for fullname
472472
473- This is s convenience wrapper around :func:`importlib.find_loader` that
474- sets the *path* argument correctly when searching for submodules, and
475- also ensures parent packages (if any) are imported before searching for
476- submodules.
473+ This is a backwards compatibility wrapper around
474+ importlib.util.find_spec that converts most failures to ImportError
475+ and only returns the loader rather than the full spec
477476 """
478477 if fullname .startswith ('.' ):
479478 msg = "Relative module name {!r} not supported" .format (fullname )
480479 raise ImportError (msg )
481- path = None
482- pkg_name = fullname .rpartition ("." )[0 ]
483- if pkg_name :
484- pkg = importlib .import_module (pkg_name )
485- path = getattr (pkg , "__path__" , None )
486- if path is None :
487- return None
488480 try :
489- return importlib .find_loader (fullname , path )
481+ spec = importlib .util . find_spec (fullname )
490482 except (ImportError , AttributeError , TypeError , ValueError ) as ex :
491483 # This hack fixes an impedance mismatch between pkgutil and
492484 # importlib, where the latter raises other errors for cases where
493485 # pkgutil previously raised ImportError
494486 msg = "Error while finding loader for {!r} ({}: {})"
495487 raise ImportError (msg .format (fullname , type (ex ), ex )) from ex
488+ return spec .loader
496489
497490
498491def extend_path (path , name ):
0 commit comments