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

Function _load_unlocked

Lib/importlib/_bootstrap.py:914–955  ·  view source on GitHub ↗
(spec)

Source from the content-addressed store, hash-verified

912 return module
913
914def _load_unlocked(spec):
915 # A helper for direct use by the import system.
916 if spec.loader is not None:
917 # Not a namespace package.
918 if not hasattr(spec.loader, 'exec_module'):
919 msg = (f"{_object_name(spec.loader)}.exec_module() not found; "
920 "falling back to load_module()")
921 _warnings.warn(msg, ImportWarning)
922 return _load_backward_compatible(spec)
923
924 module = module_from_spec(spec)
925
926 # This must be done before putting the module in sys.modules
927 # (otherwise an optimization shortcut in import.c becomes
928 # wrong).
929 spec._initializing = True
930 try:
931 sys.modules[spec.name] = module
932 try:
933 if spec.loader is None:
934 if spec.submodule_search_locations is None:
935 raise ImportError('missing loader', name=spec.name)
936 # A namespace package so do nothing.
937 else:
938 spec.loader.exec_module(module)
939 except:
940 try:
941 del sys.modules[spec.name]
942 except KeyError:
943 pass
944 raise
945 # Move the module to the end of sys.modules.
946 # We don't ensure that the import-related module attributes get
947 # set in the sys.modules replacement case. Such modules are on
948 # their own.
949 module = sys.modules.pop(spec.name)
950 sys.modules[spec.name] = module
951 _verbose_message('import {!r} # {!r}', spec.name, spec.loader)
952 finally:
953 spec._initializing = False
954
955 return module
956
957# A method used during testing of _load_unlocked() and by
958# _load_module_shim().

Callers 3

_loadFunction · 0.70
_find_and_load_unlockedFunction · 0.70
_builtin_from_nameFunction · 0.70

Calls 8

hasattrFunction · 0.85
_object_nameFunction · 0.70
module_from_specFunction · 0.70
_verbose_messageFunction · 0.70
warnMethod · 0.45
exec_moduleMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected