diff options
author | Brett Cannon <brett@python.org> | 2013-05-30 21:31:47 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2013-05-30 21:31:47 (GMT) |
commit | 357c9fb0556e0ec9d440a4874b6af19d7b0bee7b (patch) | |
tree | 9eaf7e79f980770c75961a06ce92a8f647b10dad /Lib/importlib | |
parent | 335ab5b66f432ae3713840ed2403a11c368f5406 (diff) | |
download | cpython-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')
-rw-r--r-- | Lib/importlib/_bootstrap.py | 11 | ||||
-rw-r--r-- | Lib/importlib/util.py | 2 |
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 |