]> granicus.if.org Git - python/commitdiff
importlib.test.source.util referenced variables in the 'finally' part of a
authorBrett Cannon <bcannon@gmail.com>
Thu, 5 Nov 2009 01:17:22 +0000 (01:17 +0000)
committerBrett Cannon <bcannon@gmail.com>
Thu, 5 Nov 2009 01:17:22 +0000 (01:17 +0000)
try/finally which may not have been set.

Lib/importlib/test/source/util.py
Misc/NEWS

index ca04edfa97c2027ea7aeba64a86bff450d25d61b..a881d4a5e947ed589e8c91551117168c447bb65b 100644 (file)
@@ -55,6 +55,8 @@ def create_modules(*names):
     source = 'attr = {0!r}'
     created_paths = []
     mapping = {}
+    state_manager = None
+    uncache_manager = None
     try:
         temp_dir = tempfile.gettempdir()
         mapping['.root'] = temp_dir
@@ -85,8 +87,10 @@ def create_modules(*names):
         state_manager.__enter__()
         yield mapping
     finally:
-        state_manager.__exit__(None, None, None)
-        uncache_manager.__exit__(None, None, None)
+        if state_manager is not None:
+            state_manager.__exit__(None, None, None)
+        if uncache_manager is not None:
+            uncache_manager.__exit__(None, None, None)
         # Reverse the order for path removal to unroll directory creation.
         for path in reversed(created_paths):
             if file_path.endswith('.py'):
index 57a188c0af21eb6135f72feb005209047eb60eea..f114efb7bb952198be73db79ba7bb53d2d4a5f97 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -354,6 +354,10 @@ Documentation
 Tests
 -----
 
+- Issue #7248: In importlib.test.source.util a try/finally block did not make
+  sure that some referenced objects actually were created in the block before
+  calling methods on the object.
+
 - Issue #7222: Make thread "reaping" more reliable so that reference
   leak-chasing test runs give sensible results. The previous method of
   reaping threads could return successfully while some Thread objects were