MCPcopy Index your code
hub / github.com/RustPython/RustPython / uncache

Function uncache

Lib/test/test_importlib/util.py:147–168  ·  view source on GitHub ↗

Uncache a module from sys.modules. A basic sanity check is performed to prevent uncaching modules that either cannot/shouldn't be uncached.

(*names)

Source from the content-addressed store, hash-verified

145
146@contextlib.contextmanager
147def uncache(*names):
148 """Uncache a module from sys.modules.
149
150 A basic sanity check is performed to prevent uncaching modules that either
151 cannot/shouldn't be uncached.
152
153 """
154 for name in names:
155 if name in ('sys', 'marshal'):
156 raise ValueError("cannot uncache {}".format(name))
157 try:
158 del sys.modules[name]
159 except KeyError:
160 pass
161 try:
162 yield
163 finally:
164 for name in names:
165 try:
166 del sys.modules[name]
167 except KeyError:
168 pass
169
170
171@contextlib.contextmanager

Calls 1

formatMethod · 0.45