Skip to content

Commit 589c4ff

Browse files
committed
Make it more obvious what things used in imp are snuck in through private APIs
1 parent a3c9615 commit 589c4ff

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

Lib/imp.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616
# Platform doesn't support dynamic loading.
1717
load_dynamic = None
1818

19-
# Directly exposed by this module
20-
from importlib._bootstrap import cache_from_source, source_from_cache
19+
from importlib._bootstrap import (cache_from_source, source_from_cache,
20+
SourcelessFileLoader, _ERR_MSG)
2121

22-
23-
from importlib import _bootstrap
2422
from importlib import machinery
2523
from importlib import util
2624
import importlib
@@ -117,7 +115,7 @@ def get_data(self, path):
117115
return super().get_data(path)
118116

119117

120-
class _LoadSourceCompatibility(_HackedGetData, _bootstrap.SourceFileLoader):
118+
class _LoadSourceCompatibility(_HackedGetData, machinery.SourceFileLoader):
121119

122120
"""Compatibility support for implementing load_source()."""
123121

@@ -131,12 +129,11 @@ def load_source(name, pathname, file=None):
131129
module = sys.modules[name]
132130
# To allow reloading to potentially work, use a non-hacked loader which
133131
# won't rely on a now-closed file object.
134-
module.__loader__ = _bootstrap.SourceFileLoader(name, pathname)
132+
module.__loader__ = machinery.SourceFileLoader(name, pathname)
135133
return module
136134

137135

138-
class _LoadCompiledCompatibility(_HackedGetData,
139-
_bootstrap.SourcelessFileLoader):
136+
class _LoadCompiledCompatibility(_HackedGetData, SourcelessFileLoader):
140137

141138
"""Compatibility support for implementing load_compiled()."""
142139

@@ -150,7 +147,7 @@ def load_compiled(name, pathname, file=None):
150147
module = sys.modules[name]
151148
# To allow reloading to potentially work, use a non-hacked loader which
152149
# won't rely on a now-closed file object.
153-
module.__loader__ = _bootstrap.SourcelessFileLoader(name, pathname)
150+
module.__loader__ = SourcelessFileLoader(name, pathname)
154151
return module
155152

156153

@@ -168,7 +165,7 @@ def load_package(name, path):
168165
break
169166
else:
170167
raise ValueError('{!r} is not a package'.format(path))
171-
return _bootstrap.SourceFileLoader(name, path).load_module(name)
168+
return machinery.SourceFileLoader(name, path).load_module(name)
172169

173170

174171
def load_module(name, file, filename, details):
@@ -252,7 +249,7 @@ def find_module(name, path=None):
252249
continue
253250
break # Break out of outer loop when breaking out of inner loop.
254251
else:
255-
raise ImportError(_bootstrap._ERR_MSG.format(name), name=name)
252+
raise ImportError(_ERR_MSG.format(name), name=name)
256253

257254
encoding = None
258255
if mode == 'U':

0 commit comments

Comments
 (0)