diff options
author | Guido van Rossum <guido@python.org> | 1996-10-07 23:41:54 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1996-10-07 23:41:54 (GMT) |
commit | a97b8eef70b182691b2ad460117466505dd0cb4d (patch) | |
tree | 1d684a4a888e4c6af859f72e766a70c241c6bff3 /Lib | |
parent | ccd8b19c99c353950c54d9818bb57c408df09a53 (diff) | |
download | cpython-a97b8eef70b182691b2ad460117466505dd0cb4d.zip cpython-a97b8eef70b182691b2ad460117466505dd0cb4d.tar.gz cpython-a97b8eef70b182691b2ad460117466505dd0cb4d.tar.bz2 |
Set the __file__ attribute of the imported module in both versions of
load_module(), to mimick the behavior of imp more closely.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/ihooks.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/Lib/ihooks.py b/Lib/ihooks.py index 70aa811..dfe29cf 100644 --- a/Lib/ihooks.py +++ b/Lib/ihooks.py @@ -257,13 +257,16 @@ class ModuleLoader(BasicModuleLoader): if type == FROZEN_MODULE: return self.hooks.init_frozen(name) if type == C_EXTENSION: - return self.hooks.load_dynamic(name, filename, file) - if type == PY_SOURCE: - return self.hooks.load_source(name, filename, file) - if type == PY_COMPILED: - return self.hooks.load_compiled(name, filename, file) - raise ImportError, "Unrecognized module type (%s) for %s" % \ - (`type`, name) + m = self.hooks.load_dynamic(name, filename, file) + elif type == PY_SOURCE: + m = self.hooks.load_source(name, filename, file) + elif type == PY_COMPILED: + m = self.hooks.load_compiled(name, filename, file) + else: + raise ImportError, "Unrecognized module type (%s) for %s" % \ + (`type`, name) + m.__file__ = filename + return m class FancyModuleLoader(ModuleLoader): @@ -284,6 +287,7 @@ class FancyModuleLoader(ModuleLoader): else: return ModuleLoader.load_module(self, name, stuff) m = self.hooks.add_module(name) + m.__file__ = filename exec code in m.__dict__ return m |