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

Function _load_backward_compatible

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

Source from the content-addressed store, hash-verified

876
877
878def _load_backward_compatible(spec):
879 # It is assumed that all callers have been warned about using load_module()
880 # appropriately before calling this function.
881 try:
882 spec.loader.load_module(spec.name)
883 except:
884 if spec.name in sys.modules:
885 module = sys.modules.pop(spec.name)
886 sys.modules[spec.name] = module
887 raise
888 # The module must be in sys.modules at this point!
889 # Move it to the end of sys.modules.
890 module = sys.modules.pop(spec.name)
891 sys.modules[spec.name] = module
892 if getattr(module, '__loader__', None) is None:
893 try:
894 module.__loader__ = spec.loader
895 except AttributeError:
896 pass
897 if getattr(module, '__package__', None) is None:
898 try:
899 # Since module.__path__ may not line up with
900 # spec.submodule_search_paths, we can't necessarily rely
901 # on spec.parent here.
902 module.__package__ = module.__name__
903 if not hasattr(module, '__path__'):
904 module.__package__ = spec.name.rpartition('.')[0]
905 except AttributeError:
906 pass
907 if getattr(module, '__spec__', None) is None:
908 try:
909 module.__spec__ = spec
910 except AttributeError:
911 pass
912 return module
913
914def _load_unlocked(spec):
915 # A helper for direct use by the import system.

Callers 1

_load_unlockedFunction · 0.70

Calls 5

getattrFunction · 0.85
hasattrFunction · 0.85
load_moduleMethod · 0.45
popMethod · 0.45
rpartitionMethod · 0.45

Tested by

no test coverage detected