From 1014d42dd314844c12bddee0d075521da965c60a Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Sun, 8 Mar 2009 20:53:50 +0000 Subject: Minor changes to Python source base loader. Fixed a bug where 'self' was left off a method call. Was masked by the fact the source/bytecode loader subclass is always used. Cleaned up when the source path is fetched. Also made sure ImportError is raised when a source path cannot be found. --- Lib/importlib/_bootstrap.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index 4c13c7a..b5f08eb 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -327,26 +327,30 @@ class PyLoader: @module_for_loader def load_module(self, module): """Load a source module.""" - return _load_module(module) + return self._load_module(module) def _load_module(self, module): """Initialize a module from source.""" name = module.__name__ - source_path = self.source_path(name) code_object = self.get_code(module.__name__) + # __file__ may have been set by the caller, e.g. bytecode path. if not hasattr(module, '__file__'): - module.__file__ = source_path + module.__file__ = self.source_path(name) if self.is_package(name): module.__path__ = [module.__file__.rsplit(path_sep, 1)[0]] module.__package__ = module.__name__ if not hasattr(module, '__path__'): module.__package__ = module.__package__.rpartition('.')[0] + module.__loader__ = self exec(code_object, module.__dict__) return module def get_code(self, fullname): """Get a code object from source.""" source_path = self.source_path(fullname) + if source_path is None: + message = "a source path must exist to load {0}".format(fullname) + raise ImportError(message) source = self.get_data(source_path) # Convert to universal newlines. line_endings = b'\n' -- cgit v0.12