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)
| 438 | |
| 439 | |
| 440 | def 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…