(spec)
return module
Create a module based on the provided spec.
Create a module based on the provided spec.
Create a module based on the provided spec .
def module_from_spec(spec):
    """Create a module based on the provided spec."""
    # Typically loaders will not implement create_module().
    module = None
    if hasattr(spec.loader, 'create_module'):
        # If create_module() returns `None` then it means default
        # module creation should be used.
        module = spec.loader.create_module(spec)
    elif hasattr(spec.loader, 'exec_module'):
        raise ImportError('loaders that define exec_module() '
                          'must also define create_module()')
    if module is None:
        module = _new_module(spec.name)
    _init_module_attrs(spec, module)
    return module
def module_from_spec ( spec ) : # Typically loaders will not implement create_module(). module = None if hasattr ( spec . loader , 'create_module' ) : # If create_module() returns `None` then it means default # module creation should be used. module = spec . loader . create_module ( spec ) elif hasattr ( spec . loader , 'exec_module' ) : raise ImportError ( 'loaders that define exec_module() ' 'must also define create_module()' ) if module is None : module = _new_module ( spec . name ) _init_module_attrs ( spec , module ) return module