mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
Issue #14710: Fix both pkgutil.find_loader() and get_loader() to not
raise an exception when a module doesn't exist. Thanks to Pavel Aslanov for the bug report.
This commit is contained in:
parent
065266450e
commit
8447c703d1
3 changed files with 23 additions and 1 deletions
|
@ -456,6 +456,8 @@ def get_loader(module_or_name):
|
|||
"""
|
||||
if module_or_name in sys.modules:
|
||||
module_or_name = sys.modules[module_or_name]
|
||||
if module_or_name is None:
|
||||
return None
|
||||
if isinstance(module_or_name, ModuleType):
|
||||
module = module_or_name
|
||||
loader = getattr(module, '__loader__', None)
|
||||
|
@ -487,7 +489,7 @@ def find_loader(fullname):
|
|||
# pkgutil previously raised ImportError
|
||||
msg = "Error while finding loader for {!r} ({}: {})"
|
||||
raise ImportError(msg.format(fullname, type(ex), ex)) from ex
|
||||
return spec.loader
|
||||
return spec.loader if spec is not None else None
|
||||
|
||||
|
||||
def extend_path(path, name):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue