From: Guido van Rossum Date: Mon, 7 Oct 1996 23:41:54 +0000 (+0000) Subject: Set the __file__ attribute of the imported module in both versions of X-Git-Tag: v1.4~144 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a97b8eef70b182691b2ad460117466505dd0cb4d;p=thirdparty%2FPython%2Fcpython.git Set the __file__ attribute of the imported module in both versions of load_module(), to mimick the behavior of imp more closely. --- diff --git a/Lib/ihooks.py b/Lib/ihooks.py index 70aa8114d97e..dfe29cfea961 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