Issue #14605: Stop having implicit entries for sys.meta_path.

ImportWarning is raised if sys.meta_path is found to be empty.
This commit is contained in:
Brett Cannon 2012-04-27 14:01:58 -04:00
parent 3c6ea1c14d
commit ce418b448f
8 changed files with 3006 additions and 2983 deletions

View file

@ -956,8 +956,9 @@ def _resolve_name(name, package, level):
def _find_module(name, path):
"""Find a module's loader."""
meta_path = sys.meta_path + _IMPLICIT_META_PATH
for finder in meta_path:
if not sys.meta_path:
_warnings.warn('sys.meta_path is empty', ImportWarning)
for finder in sys.meta_path:
loader = finder.find_module(name, path)
if loader is not None:
# The parent import may have already imported this module.
@ -986,8 +987,6 @@ def _sanity_check(name, package, level):
raise ValueError("Empty module name")
_IMPLICIT_META_PATH = [BuiltinImporter, FrozenImporter, PathFinder]
_ERR_MSG = 'No module named {!r}'
def _find_and_load(name, import_):
@ -1195,3 +1194,4 @@ def _install(sys_module, _imp_module):
(SourcelessFileLoader, _suffix_list(2), True)]
sys.path_hooks.extend([FileFinder.path_hook(*supported_loaders),
_imp.NullImporter])
sys.meta_path.extend([BuiltinImporter, FrozenImporter, PathFinder])