summaryrefslogtreecommitdiffstats
path: root/Lib/pkgutil.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2014-05-23 16:30:37 (GMT)
committerBrett Cannon <brett@python.org>2014-05-23 16:30:37 (GMT)
commit8447c703d1fd0107a52b15de7ce3a7056e1ec160 (patch)
tree1c6db7c398072ba929180cab46acf52bad84fec0 /Lib/pkgutil.py
parent065266450ea5519a43bcc199e48d304f1e7038e8 (diff)
downloadcpython-8447c703d1fd0107a52b15de7ce3a7056e1ec160.zip
cpython-8447c703d1fd0107a52b15de7ce3a7056e1ec160.tar.gz
cpython-8447c703d1fd0107a52b15de7ce3a7056e1ec160.tar.bz2
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.
Diffstat (limited to 'Lib/pkgutil.py')
-rw-r--r--Lib/pkgutil.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py
index e42b6eb..a54e947 100644
--- a/Lib/pkgutil.py
+++ b/Lib/pkgutil.py
@@ -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):