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

Function module_from_spec

Lib/importlib/_bootstrap.py:779–793  ·  view source on GitHub ↗

Create a module based on the provided spec.

(spec)

Source from the content-addressed store, hash-verified

777
778
779def module_from_spec(spec):
780 """Create a module based on the provided spec."""
781 # Typically loaders will not implement create_module().
782 module = None
783 if hasattr(spec.loader, 'create_module'):
784 # If create_module() returns `None` then it means default
785 # module creation should be used.
786 module = spec.loader.create_module(spec)
787 elif hasattr(spec.loader, 'exec_module'):
788 raise ImportError('loaders that define exec_module() '
789 'must also define create_module()')
790 if module is None:
791 module = _new_module(spec.name)
792 _init_module_attrs(spec, module)
793 return module
794
795
796def _module_repr_from_spec(spec):

Callers 1

_load_unlockedFunction · 0.85

Calls 3

_new_moduleFunction · 0.85
_init_module_attrsFunction · 0.85
create_moduleMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…