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

Function _find_and_load

Lib/importlib/_bootstrap.py:1360–1383  ·  view source on GitHub ↗

Find and load the module.

(name, import_)

Source from the content-addressed store, hash-verified

1358
1359
1360def _find_and_load(name, import_):
1361 """Find and load the module."""
1362
1363 # Optimization: we avoid unneeded module locking if the module
1364 # already exists in sys.modules and is fully initialized.
1365 module = sys.modules.get(name, _NEEDS_LOADING)
1366 if (module is _NEEDS_LOADING or
1367 getattr(getattr(module, "__spec__", None), "_initializing", False)):
1368 with _ModuleLockManager(name):
1369 module = sys.modules.get(name, _NEEDS_LOADING)
1370 if module is _NEEDS_LOADING:
1371 return _find_and_load_unlocked(name, import_)
1372
1373 # Optimization: only call _bootstrap._lock_unlock_module() if
1374 # module.__spec__._initializing is True.
1375 # NOTE: because of this, initializing must be set *before*
1376 # putting the new module in sys.modules.
1377 _lock_unlock_module(name)
1378
1379 if module is None:
1380 message = f'import of {name} halted; None in sys.modules'
1381 raise ModuleNotFoundError(message, name=name)
1382
1383 return module
1384
1385
1386def _gcd_import(name, package=None, level=0):

Callers 1

_gcd_importFunction · 0.70

Calls 5

getattrFunction · 0.85
_ModuleLockManagerClass · 0.70
_find_and_load_unlockedFunction · 0.70
_lock_unlock_moduleFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected