MCPcopy Index your code
hub / github.com/python/cpython / modules_cleanup

Function modules_cleanup

Lib/test/support/import_helper.py:267–282  ·  view source on GitHub ↗
(oldmodules)

Source from the content-addressed store, hash-verified

265
266
267def modules_cleanup(oldmodules):
268 # Encoders/decoders are registered permanently within the internal
269 # codec cache. If we destroy the corresponding modules their
270 # globals will be set to None which will trip up the cached functions.
271 encodings = [(k, v) for k, v in sys.modules.items()
272 if k.startswith('encodings.')]
273 sys.modules.clear()
274 sys.modules.update(encodings)
275 # XXX: This kind of problem can affect more than just encodings.
276 # In particular extension modules (such as _ssl) don't cope
277 # with reloading properly. Really, test modules should be cleaning
278 # out the test specific modules they know they added (ala test_runpy)
279 # rather than relying on this function (as test_importhooks and test_pkg
280 # do currently). Implicitly imported *real* modules should be left alone
281 # (see issue 10556).
282 sys.modules.update(oldmodules)
283
284
285@contextlib.contextmanager

Callers 1

isolated_modulesFunction · 0.85

Calls 4

itemsMethod · 0.45
startswithMethod · 0.45
clearMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…