1. Armin Rigo
  2. cpython-withatomic

Commits

Tim Peters  committed db38c1e

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.

  • Participants
  • Parent commits fbb5428
  • Branches legacy-trunk

Comments (0)

Files changed (2)

File Lib/ihooks.py

View file
  • Ignore whitespace
         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
 
 

File Lib/imputil.py

View file
  • Ignore whitespace
 
         # 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