summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/_bootstrap.py11
-rw-r--r--Lib/importlib/util.py2
2 files changed, 10 insertions, 3 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 739279f..f5b71ba 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -484,7 +484,8 @@ def _verbose_message(message, *args, verbosity=1):
print(message.format(*args), file=sys.stderr)
-class ModuleManager:
+# Written as a class only because contextlib is not available.
+class _ModuleManager:
"""Context manager which returns the module to be loaded.
@@ -516,6 +517,12 @@ class ModuleManager:
del sys.modules[self._name]
+def module_to_load(name):
+ """Return a context manager which provides the module object to load."""
+ # Hiding _ModuleManager behind a function for better naming.
+ return _ModuleManager(name)
+
+
def set_package(fxn):
"""Set __package__ on the returned module."""
def set_package_wrapper(*args, **kwargs):
@@ -559,7 +566,7 @@ def module_for_loader(fxn):
"""
def module_for_loader_wrapper(self, fullname, *args, **kwargs):
- with ModuleManager(fullname) as module:
+ with module_to_load(fullname) as module:
module.__loader__ = self
try:
is_package = self.is_package(fullname)
diff --git a/Lib/importlib/util.py b/Lib/importlib/util.py
index f817a40..74eef2a 100644
--- a/Lib/importlib/util.py
+++ b/Lib/importlib/util.py
@@ -1,6 +1,6 @@
"""Utility code for constructing importers, etc."""
-from ._bootstrap import ModuleManager
+from ._bootstrap import module_to_load
from ._bootstrap import module_for_loader
from ._bootstrap import set_loader
from ._bootstrap import set_package