summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/_bootstrap.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-08-10 21:41:23 (GMT)
committerBrett Cannon <brett@python.org>2012-08-10 21:41:23 (GMT)
commitf410ce8c0989ef14f0f935e256d82e96f5e0602b (patch)
treec27335efcfa4954c4e583c8dcae29eaae9541983 /Lib/importlib/_bootstrap.py
parente9175bd0af440c92364466b22267a93890b44015 (diff)
downloadcpython-f410ce8c0989ef14f0f935e256d82e96f5e0602b.zip
cpython-f410ce8c0989ef14f0f935e256d82e96f5e0602b.tar.gz
cpython-f410ce8c0989ef14f0f935e256d82e96f5e0602b.tar.bz2
Issue #15502: Refactor some code.
Diffstat (limited to 'Lib/importlib/_bootstrap.py')
-rw-r--r--Lib/importlib/_bootstrap.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index b79fdcc..34d54bb 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -607,6 +607,21 @@ def _requires_frozen(fxn):
return _requires_frozen_wrapper
+def _find_module_shim(self, fullname):
+ """Try to find a loader for the specified module by delegating to
+ self.find_loader()."""
+ # Call find_loader(). If it returns a string (indicating this
+ # is a namespace package portion), generate a warning and
+ # return None.
+ loader, portions = self.find_loader(fullname)
+ if loader is None and len(portions):
+ msg = "Not importing directory {}: missing __init__"
+ _warnings.warn(msg.format(portions[0]), ImportWarning)
+ return loader
+
+
+
+
# Loaders #####################################################################
class BuiltinImporter:
@@ -1305,17 +1320,7 @@ class FileFinder:
"""Invalidate the directory mtime."""
self._path_mtime = -1
- def find_module(self, fullname):
- """Try to find a loader for the specified module."""
- # Call find_loader(). If it returns a string (indicating this
- # is a namespace package portion), generate a warning and
- # return None.
- loader, portions = self.find_loader(fullname)
- assert len(portions) in [0, 1]
- if loader is None and len(portions):
- msg = "Not importing directory {}: missing __init__"
- _warnings.warn(msg.format(portions[0]), ImportWarning)
- return loader
+ find_module = _find_module_shim
def find_loader(self, fullname):
"""Try to find a loader for the specified module, or the namespace