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

Function ensure_module_imported

Lib/test/support/import_helper.py:440–454  ·  view source on GitHub ↗

Return the corresponding module. If it was already imported then return that. Otherwise, try importing it (optionally clear it first if None). If that fails then create a new empty module. It can be helpful to combine this with ready_to_import() and/or isolated_modules().

(name, *, clearnone=True)

Source from the content-addressed store, hash-verified

438
439
440def ensure_module_imported(name, *, clearnone=True):
441 """Return the corresponding module.
442
443 If it was already imported then return that. Otherwise, try
444 importing it (optionally clear it first if None). If that fails
445 then create a new empty module.
446
447 It can be helpful to combine this with ready_to_import() and/or
448 isolated_modules().
449 """
450 if sys.modules.get(name) is not None:
451 mod = sys.modules[name]
452 else:
453 mod, _, _ = _ensure_module(name, False, True, clearnone)
454 return mod

Callers

nothing calls this directly

Calls 2

_ensure_moduleFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…