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

Function _spec_from_module

Lib/importlib/_bootstrap.py:675–710  ·  view source on GitHub ↗
(module, loader=None, origin=None)

Source from the content-addressed store, hash-verified

673
674
675def _spec_from_module(module, loader=None, origin=None):
676 # This function is meant for use in _setup().
677 try:
678 spec = module.__spec__
679 except AttributeError:
680 pass
681 else:
682 if spec is not None:
683 return spec
684
685 name = module.__name__
686 if loader is None:
687 try:
688 loader = module.__loader__
689 except AttributeError:
690 # loader will stay None.
691 pass
692 try:
693 location = module.__file__
694 except AttributeError:
695 location = None
696 if origin is None:
697 if loader is not None:
698 origin = getattr(loader, '_ORIGIN', None)
699 if not origin and location is not None:
700 origin = location
701 try:
702 submodule_search_locations = list(module.__path__)
703 except AttributeError:
704 submodule_search_locations = None
705
706 spec = ModuleSpec(name, loader, origin=origin)
707 spec._set_fileattr = False if location is None else (origin == location)
708 spec.cached = None
709 spec.submodule_search_locations = submodule_search_locations
710 return spec
711
712
713def _init_module_attrs(spec, module, *, override=False):

Callers 1

_setupFunction · 0.85

Calls 2

listClass · 0.85
ModuleSpecClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…