(spec)
| 839 | return module |
| 840 | |
| 841 | def _load_unlocked(spec): |
| 842 | # A helper for direct use by the import system. |
| 843 | module = module_from_spec(spec) |
| 844 | |
| 845 | # This must be done before putting the module in sys.modules |
| 846 | # (otherwise an optimization shortcut in import.c becomes |
| 847 | # wrong). |
| 848 | spec._initializing = True |
| 849 | try: |
| 850 | sys.modules[spec.name] = module |
| 851 | try: |
| 852 | if spec.loader is None: |
| 853 | if spec.submodule_search_locations is None: |
| 854 | raise ImportError('missing loader', name=spec.name) |
| 855 | # A namespace package so do nothing. |
| 856 | else: |
| 857 | spec.loader.exec_module(module) |
| 858 | except: |
| 859 | try: |
| 860 | del sys.modules[spec.name] |
| 861 | except KeyError: |
| 862 | pass |
| 863 | raise |
| 864 | # Move the module to the end of sys.modules. |
| 865 | # We don't ensure that the import-related module attributes get |
| 866 | # set in the sys.modules replacement case. Such modules are on |
| 867 | # their own. |
| 868 | module = sys.modules.pop(spec.name) |
| 869 | sys.modules[spec.name] = module |
| 870 | _verbose_message('import {!r} # {!r}', spec.name, spec.loader) |
| 871 | finally: |
| 872 | spec._initializing = False |
| 873 | |
| 874 | return module |
| 875 | |
| 876 | # A method used during testing of _load_unlocked(). |
| 877 | def _load(spec): |
no test coverage detected
searching dependent graphs…