@@ -124,7 +124,8 @@ def import_module(name, deprecated=False):
124124def _save_and_remove_module (name , orig_modules ):
125125 """Helper function to save and remove a module from sys.modules
126126
127- Raise ImportError if the module can't be imported."""
127+ Raise ImportError if the module can't be imported.
128+ """
128129 # try to import the module and raise an error if it can't be imported
129130 if name not in sys .modules :
130131 __import__ (name )
@@ -137,7 +138,8 @@ def _save_and_remove_module(name, orig_modules):
137138def _save_and_block_module (name , orig_modules ):
138139 """Helper function to save and block a module in sys.modules
139140
140- Return True if the module was in sys.modules, False otherwise."""
141+ Return True if the module was in sys.modules, False otherwise.
142+ """
141143 saved = True
142144 try :
143145 orig_modules [name ] = sys .modules [name ]
@@ -159,18 +161,30 @@ def anticipate_failure(condition):
159161
160162
161163def import_fresh_module (name , fresh = (), blocked = (), deprecated = False ):
162- """Imports and returns a module, deliberately bypassing the sys.modules cache
163- and importing a fresh copy of the module. Once the import is complete,
164- the sys.modules cache is restored to its original state.
164+ """Import and return a module, deliberately bypassing sys.modules.
165165
166- Modules named in fresh are also imported anew if needed by the import.
167- If one of these modules can't be imported, None is returned.
166+ This function imports and returns a fresh copy of the named Python module
167+ by removing the named module from sys.modules before doing the import.
168+ Note that unlike reload, the original module is not affected by
169+ this operation.
168170
169- Importing of modules named in blocked is prevented while the fresh import
170- takes place .
171+ *fresh* is an iterable of additional module names that are also removed
172+ from the sys.modules cache before doing the import .
171173
172- If deprecated is True, any module or package deprecation messages
173- will be suppressed."""
174+ *blocked* is an iterable of module names that are replaced with None
175+ in the module cache during the import to ensure that attempts to import
176+ them raise ImportError.
177+
178+ The named module and any modules named in the *fresh* and *blocked*
179+ parameters are saved before starting the import and then reinserted into
180+ sys.modules when the fresh import is complete.
181+
182+ Module and package deprecation messages are suppressed during this import
183+ if *deprecated* is True.
184+
185+ This function will raise ImportError if the named module cannot be
186+ imported.
187+ """
174188 # NOTE: test_heapq, test_json and test_warnings include extra sanity checks
175189 # to make sure that this utility function is working as expected
176190 with _ignore_deprecated_imports (deprecated ):
0 commit comments