summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/_bootstrap.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2013-05-30 21:31:47 (GMT)
committerBrett Cannon <brett@python.org>2013-05-30 21:31:47 (GMT)
commit357c9fb0556e0ec9d440a4874b6af19d7b0bee7b (patch)
tree9eaf7e79f980770c75961a06ce92a8f647b10dad /Lib/importlib/_bootstrap.py
parent335ab5b66f432ae3713840ed2403a11c368f5406 (diff)
downloadcpython-357c9fb0556e0ec9d440a4874b6af19d7b0bee7b.zip
cpython-357c9fb0556e0ec9d440a4874b6af19d7b0bee7b.tar.gz
cpython-357c9fb0556e0ec9d440a4874b6af19d7b0bee7b.tar.bz2
Rename importlib.util.ModuleManager to module_to_load so that the name
explains better what the context manager is providing.
Diffstat (limited to 'Lib/importlib/_bootstrap.py')
-rw-r--r--Lib/importlib/_bootstrap.py11
1 files changed, 9 insertions, 2 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)