]> granicus.if.org Git - python/commitdiff
ihooks FancyModuleLoader.load_module()
authorTim Peters <tim.peters@gmail.com>
Wed, 4 Aug 2004 02:29:12 +0000 (02:29 +0000)
committerTim Peters <tim.peters@gmail.com>
Wed, 4 Aug 2004 02:29:12 +0000 (02:29 +0000)
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
Lib/imputil.py

index 936a950de07e2d48a32df89318a330ef35ba3d5a..f5b93ab9cf3647bd32ce6ccf09a27418a1eec09d 100644 (file)
@@ -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
 
 
index 04111dcaa612cbc53c4dcfca5e4260edd1e49179..e6ad7ecac4ea0ce2e779d3a68f1326947bc8227b 100644 (file)
@@ -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