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

Function sys_modules_context

Lib/test/test_importlib/test_namespace_pkgs.py:21–36  ·  view source on GitHub ↗

Make sure sys.modules is the same object and has the same content when exiting the context as when entering. Similar to importlib.test.util.uncache, but doesn't require explicit names.

()

Source from the content-addressed store, hash-verified

19
20@contextlib.contextmanager
21def sys_modules_context():
22 """
23 Make sure sys.modules is the same object and has the same content
24 when exiting the context as when entering.
25
26 Similar to importlib.test.util.uncache, but doesn't require explicit
27 names.
28 """
29 sys_modules_saved = sys.modules
30 sys_modules_copy = sys.modules.copy()
31 try:
32 yield
33 finally:
34 sys.modules = sys_modules_saved
35 sys.modules.clear()
36 sys.modules.update(sys_modules_copy)
37
38
39@contextlib.contextmanager

Callers 1

namespace_tree_contextFunction · 0.85

Calls 3

copyMethod · 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…