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

Function _exec

Lib/importlib/_bootstrap.py:848–875  ·  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

846
847# Used by importlib.reload() and _load_module_shim().
848def _exec(spec, module):
849 """Execute the spec's specified module in an existing module's namespace."""
850 name = spec.name
851 with _ModuleLockManager(name):
852 if sys.modules.get(name) is not module:
853 msg = f'module {name!r} not in sys.modules'
854 raise ImportError(msg, name=name)
855 try:
856 if spec.loader is None:
857 if spec.submodule_search_locations is None:
858 raise ImportError('missing loader', name=spec.name)
859 # Namespace package.
860 _init_module_attrs(spec, module, override=True)
861 else:
862 _init_module_attrs(spec, module, override=True)
863 if not hasattr(spec.loader, 'exec_module'):
864 msg = (f"{_object_name(spec.loader)}.exec_module() not found; "
865 "falling back to load_module()")
866 _warnings.warn(msg, ImportWarning)
867 spec.loader.load_module(name)
868 else:
869 spec.loader.exec_module(module)
870 finally:
871 # Update the order of insertion into sys.modules for module
872 # clean-up at shutdown.
873 module = sys.modules.pop(spec.name)
874 sys.modules[spec.name] = module
875 return module
876
877
878def _load_backward_compatible(spec):

Callers 1

_load_module_shimFunction · 0.70

Calls 9

hasattrFunction · 0.85
_ModuleLockManagerClass · 0.70
_init_module_attrsFunction · 0.70
_object_nameFunction · 0.70
getMethod · 0.45
warnMethod · 0.45
load_moduleMethod · 0.45
exec_moduleMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected