@@ -130,8 +130,8 @@ def import_module(name, deprecated=False, *, required_on=()):
130130def _save_and_remove_module (name , orig_modules ):
131131 """Helper function to save and remove a module from sys.modules
132132
133- Raise ImportError if the module can't be imported.
134- """
133+ Raise ImportError if the module can't be imported.
134+ """
135135 # try to import the module and raise an error if it can't be imported
136136 if name not in sys .modules :
137137 __import__ (name )
@@ -144,7 +144,8 @@ def _save_and_remove_module(name, orig_modules):
144144def _save_and_block_module (name , orig_modules ):
145145 """Helper function to save and block a module in sys.modules
146146
147- Return True if the module was in sys.modules, False otherwise."""
147+ Return True if the module was in sys.modules, False otherwise.
148+ """
148149 saved = True
149150 try :
150151 orig_modules [name ] = sys .modules [name ]
@@ -166,18 +167,30 @@ def anticipate_failure(condition):
166167
167168
168169def import_fresh_module (name , fresh = (), blocked = (), deprecated = False ):
169- """Imports and returns a module, deliberately bypassing the sys.modules cache
170- and importing a fresh copy of the module. Once the import is complete,
171- the sys.modules cache is restored to its original state.
170+ """Import and return a module, deliberately bypassing sys.modules.
172171
173- Modules named in fresh are also imported anew if needed by the import.
174- If one of these modules can't be imported, None is returned.
172+ This function imports and returns a fresh copy of the named Python module
173+ by removing the named module from sys.modules before doing the import.
174+ Note that unlike reload, the original module is not affected by
175+ this operation.
175176
176- Importing of modules named in blocked is prevented while the fresh import
177- takes place .
177+ *fresh* is an iterable of additional module names that are also removed
178+ from the sys.modules cache before doing the import .
178179
179- If deprecated is True, any module or package deprecation messages
180- will be suppressed."""
180+ *blocked* is an iterable of module names that are replaced with None
181+ in the module cache during the import to ensure that attempts to import
182+ them raise ImportError.
183+
184+ The named module and any modules named in the *fresh* and *blocked*
185+ parameters are saved before starting the import and then reinserted into
186+ sys.modules when the fresh import is complete.
187+
188+ Module and package deprecation messages are suppressed during this import
189+ if *deprecated* is True.
190+
191+ This function will raise ImportError if the named module cannot be
192+ imported.
193+ """
181194 # NOTE: test_heapq, test_json and test_warnings include extra sanity checks
182195 # to make sure that this utility function is working as expected
183196 with _ignore_deprecated_imports (deprecated ):
0 commit comments