• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Subset of importlib.abc used to reduce importlib.util imports."""
2from . import _bootstrap
3import abc
4
5
6class Loader(metaclass=abc.ABCMeta):
7
8    """Abstract base class for import loaders."""
9
10    def create_module(self, spec):
11        """Return a module to initialize and into which to load.
12
13        This method should raise ImportError if anything prevents it
14        from creating a new module.  It may return None to indicate
15        that the spec should create the new module.
16        """
17        # By default, defer to default semantics for the new module.
18        return None
19
20    # We don't define exec_module() here since that would break
21    # hasattr checks we do to support backward compatibility.
22
23    def load_module(self, fullname):
24        """Return the loaded module.
25
26        The module must be added to sys.modules and have import-related
27        attributes set properly.  The fullname is a str.
28
29        ImportError is raised on failure.
30
31        This method is deprecated in favor of loader.exec_module(). If
32        exec_module() exists then it is used to provide a backwards-compatible
33        functionality for this method.
34
35        """
36        if not hasattr(self, 'exec_module'):
37            raise ImportError
38        # Warning implemented in _load_module_shim().
39        return _bootstrap._load_module_shim(self, fullname)
40