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

Function ready_to_import

Lib/test/support/import_helper.py:306–325  ·  view source on GitHub ↗
(name=None, source="")

Source from the content-addressed store, hash-verified

304
305@contextlib.contextmanager
306def ready_to_import(name=None, source=""):
307 from test.support import script_helper
308
309 # 1. Sets up a temporary directory and removes it afterwards
310 # 2. Creates the module file
311 # 3. Temporarily clears the module from sys.modules (if any)
312 # 4. Reverts or removes the module when cleaning up
313 name = name or "spam"
314 with temp_dir() as tempdir:
315 path = script_helper.make_script(tempdir, name, source)
316 old_module = sys.modules.pop(name, None)
317 try:
318 sys.path.insert(0, tempdir)
319 yield name, path
320 finally:
321 sys.path.remove(tempdir)
322 if old_module is not None:
323 sys.modules[name] = old_module
324 else:
325 sys.modules.pop(name, None)
326
327
328def ensure_lazy_imports(imported_module, modules_to_block):

Calls 5

temp_dirFunction · 0.85
make_scriptMethod · 0.45
popMethod · 0.45
insertMethod · 0.45
removeMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…