Make it more obvious what things used in imp are snuck in through private APIs

This commit is contained in:
Brett Cannon 2013-06-14 22:29:58 -04:00
parent a3c96154d2
commit 589c4fffd2
1 changed files with 8 additions and 11 deletions

View File

@ -16,11 +16,9 @@ except ModuleNotFoundError:
# Platform doesn't support dynamic loading. # Platform doesn't support dynamic loading.
load_dynamic = None load_dynamic = None
# Directly exposed by this module from importlib._bootstrap import (cache_from_source, source_from_cache,
from importlib._bootstrap import cache_from_source, source_from_cache SourcelessFileLoader, _ERR_MSG)
from importlib import _bootstrap
from importlib import machinery from importlib import machinery
from importlib import util from importlib import util
import importlib import importlib
@ -117,7 +115,7 @@ class _HackedGetData:
return super().get_data(path) return super().get_data(path)
class _LoadSourceCompatibility(_HackedGetData, _bootstrap.SourceFileLoader): class _LoadSourceCompatibility(_HackedGetData, machinery.SourceFileLoader):
"""Compatibility support for implementing load_source().""" """Compatibility support for implementing load_source()."""
@ -131,12 +129,11 @@ def load_source(name, pathname, file=None):
module = sys.modules[name] module = sys.modules[name]
# To allow reloading to potentially work, use a non-hacked loader which # To allow reloading to potentially work, use a non-hacked loader which
# won't rely on a now-closed file object. # won't rely on a now-closed file object.
module.__loader__ = _bootstrap.SourceFileLoader(name, pathname) module.__loader__ = machinery.SourceFileLoader(name, pathname)
return module return module
class _LoadCompiledCompatibility(_HackedGetData, class _LoadCompiledCompatibility(_HackedGetData, SourcelessFileLoader):
_bootstrap.SourcelessFileLoader):
"""Compatibility support for implementing load_compiled().""" """Compatibility support for implementing load_compiled()."""
@ -150,7 +147,7 @@ def load_compiled(name, pathname, file=None):
module = sys.modules[name] module = sys.modules[name]
# To allow reloading to potentially work, use a non-hacked loader which # To allow reloading to potentially work, use a non-hacked loader which
# won't rely on a now-closed file object. # won't rely on a now-closed file object.
module.__loader__ = _bootstrap.SourcelessFileLoader(name, pathname) module.__loader__ = SourcelessFileLoader(name, pathname)
return module return module
@ -168,7 +165,7 @@ def load_package(name, path):
break break
else: else:
raise ValueError('{!r} is not a package'.format(path)) raise ValueError('{!r} is not a package'.format(path))
return _bootstrap.SourceFileLoader(name, path).load_module(name) return machinery.SourceFileLoader(name, path).load_module(name)
def load_module(name, file, filename, details): def load_module(name, file, filename, details):
@ -252,7 +249,7 @@ def find_module(name, path=None):
continue continue
break # Break out of outer loop when breaking out of inner loop. break # Break out of outer loop when breaking out of inner loop.
else: else:
raise ImportError(_bootstrap._ERR_MSG.format(name), name=name) raise ImportError(_ERR_MSG.format(name), name=name)
encoding = None encoding = None
if mode == 'U': if mode == 'U':