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

Function _exec

Lib/importlib/_bootstrap.py:818–839  ·  view source on GitHub ↗

Execute the spec's specified module in an existing module's namespace.

(spec, module)

Source from the content-addressed store, hash-verified

816
817# Used by importlib.reload().
818def _exec(spec, module):
819 """Execute the spec's specified module in an existing module's namespace."""
820 name = spec.name
821 with _ModuleLockManager(name):
822 if sys.modules.get(name) is not module:
823 msg = f'module {name!r} not in sys.modules'
824 raise ImportError(msg, name=name)
825 try:
826 if spec.loader is None:
827 if spec.submodule_search_locations is None:
828 raise ImportError('missing loader', name=spec.name)
829 # Namespace package.
830 _init_module_attrs(spec, module, override=True)
831 else:
832 _init_module_attrs(spec, module, override=True)
833 spec.loader.exec_module(module)
834 finally:
835 # Update the order of insertion into sys.modules for module
836 # clean-up at shutdown.
837 module = sys.modules.pop(spec.name)
838 sys.modules[spec.name] = module
839 return module
840
841def _load_unlocked(spec):
842 # A helper for direct use by the import system.

Callers

nothing calls this directly

Calls 5

_ModuleLockManagerClass · 0.85
_init_module_attrsFunction · 0.85
getMethod · 0.45
exec_moduleMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…