summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2009-03-08 20:53:50 (GMT)
committerBrett Cannon <bcannon@gmail.com>2009-03-08 20:53:50 (GMT)
commit1014d42dd314844c12bddee0d075521da965c60a (patch)
treea51ae26ee305469d361ab26b02fc59a0f973f2e9 /Lib
parent79925fdbfe42350d84a2bd938b2bccc1a48a2f0e (diff)
downloadcpython-1014d42dd314844c12bddee0d075521da965c60a.zip
cpython-1014d42dd314844c12bddee0d075521da965c60a.tar.gz
cpython-1014d42dd314844c12bddee0d075521da965c60a.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/importlib/_bootstrap.py10
1 files 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'