Add a reset_name argument to importlib.util.module_to_load in order to

control whether to reset the module's __name__ attribute in case a
reload is being done.
This commit is contained in:
Brett Cannon 2013-05-31 18:11:17 -04:00
parent 028d51236a
commit b60a43eabf
3 changed files with 30 additions and 2 deletions

View file

@ -788,7 +788,7 @@ an :term:`importer`.
.. versionadded:: 3.3
.. function:: module_to_load(name)
.. function:: module_to_load(name, *, reset_name=True)
Returns a :term:`context manager` which provides the module to load. The
module will either come from :attr:`sys.modules` in the case of reloading or
@ -796,6 +796,10 @@ an :term:`importer`.
:attr:`sys.modules` occurs if the module was new and an exception was
raised.
If **reset_name** is true and the module requested is being reloaded then
the module's :attr:`__name__` attribute will
be reset to **name**, else it will be left untouched.
.. versionadded:: 3.4
.. decorator:: module_for_loader