Commits

Anonymous committed 52fb003

Fixed docstrings in engine.py. Fixed ImportEngine.from_engine to take the right parameters.

Comments (0)

Files changed (1)

Lib/importlib/engine.py

     """Decorator to handle selecting the proper module for loaders.
 
     The decorated function is passed the module to use instead of the module
-    name. The module passed in to the function is either from sys.modules if
+    name. The module passed in to the function is either from engine.modules if
     it already exists or is a new module which has __name__ set and is inserted
-    into sys.modules. If an exception is raised and the decorator created the
-    module it is subsequently removed from sys.modules.
+    into engine.modules. If an exception is raised and the decorator created the
+    module it is subsequently removed from engine.modules.
 
     The decorator assumes that the decorated function takes the module name as
-    the second argument.
+    the second argument and an ImportEngine object as the third.
 
     """
     def decorated(self, fullname, engine, *args, **kwargs):
 
 class PathFinder:
 
-    """Meta path finder for sys.(path|path_hooks|path_importer_cache)."""
+    """Meta path finder for ImportEngine.(path|path_hooks|path_importer_cache)."""
 
     @classmethod
     def _path_hooks(cls, path, hooks=None, engine=None):
         """Search sequence of hooks for a finder for 'path'.
 
-        If 'hooks' is false then use sys.path_hooks.
+        If 'hooks' is false then use ImportEngine.path_hooks.
 
         """
         if not hooks:
 
     @classmethod
     def _path_importer_cache(cls, path, engine=None, default=None):
-        """Get the finder for the path from sys.path_importer_cache.
+        """Get the finder for the path from ImportEngine.path_importer_cache.
 
         If the path is not in the cache, find the appropriate finder and cache
         it. If None is cached, get the default finder and cache that
 
     @classmethod
     def find_module(cls, fullname, path=None, engine=None):
-        """Find the module on sys.path or 'path' based on sys.path_hooks and
+        """Find the module on sys.path or 'path' based on ImportEngine.path_hooks and
         sys.path_importer_cache."""
         if not path:
             if engine:
 
     @classmethod
     def _path_hooks(cls, path, engine=None):
-        """Search sys.path_hooks as well as implicit path hooks."""
+        """Search ImportEngine.path_hooks as well as implicit path hooks."""
         try:
             return super()._path_hooks(path, engine=engine)
         except ImportError:
                         pass
             return module
 
-    def from_engine(self, other):
+    @classmethod
+    def from_engine(cls, other):
         """
         Return an ImportEngine with a copy of the global import state.
         """
         import copy
         engine = ImportEngine()
 
-        engine.modules = copy.copy(self.modules)
-        engine.path = copy.copy(self.path)
-        engine.path_hooks = copy.copy(self.path_hooks)
-        engine.meta_path = copy.copy(self.meta_path)
-        engine.path_importer_cache = copy.copy(self.path_importer_cache)
+        engine.modules = copy.copy(other.modules)
+        engine.path = copy.copy(other.path)
+        engine.path_hooks = copy.copy(other.path_hooks)
+        engine.meta_path = copy.copy(other.meta_path)
+        engine.path_importer_cache = copy.copy(other.path_importer_cache)
 
         return engine
 
 class GlobalImportEngine(ImportEngine):
+    """
+    Subclass of ImportEngine which uses and writes to the global import-related
+    state in sys.
+    """
     def __init__(self):
         # Don't want to call super().__init__() since it would overwrite
         # global state.