Rename importlib.util.ModuleManager to module_to_load so that the name

explains better what the context manager is providing.
This commit is contained in:
Brett Cannon 2013-05-30 17:31:47 -04:00
parent 335ab5b66f
commit 357c9fb055
6 changed files with 3568 additions and 3547 deletions

View file

@ -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)