From 3d3cfdb4994ed672436e3e16b66ac1b9349543db Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Wed, 4 Aug 2004 02:29:12 +0000 Subject: ihooks FancyModuleLoader.load_module() imputils Importer._process_result(): remove name from modules dict if exec fails. This is what all the builtin importers do now, new in 2.4. --- Lib/ihooks.py | 8 +++++++- Lib/imputil.py | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Lib/ihooks.py b/Lib/ihooks.py index 936a950..f5b93ab 100644 --- a/Lib/ihooks.py +++ b/Lib/ihooks.py @@ -322,7 +322,13 @@ class FancyModuleLoader(ModuleLoader): if path: m.__path__ = path m.__file__ = filename - exec code in m.__dict__ + try: + exec code in m.__dict__ + except: + d = self.hooks.modules_dict() + if name in d: + del d[name] + raise return m diff --git a/Lib/imputil.py b/Lib/imputil.py index 04111dc..e6ad7ec 100644 --- a/Lib/imputil.py +++ b/Lib/imputil.py @@ -297,7 +297,12 @@ class Importer: # execute the code within the module's namespace if not is_module: - exec code in module.__dict__ + try: + exec code in module.__dict__ + except: + if fqname in sys.modules: + del sys.modules[fqname] + raise # fetch from sys.modules instead of returning module directly. # also make module's __name__ agree with fqname, in case -- cgit v0.12