]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #15828: Don't try to close a file if imp.find_module() doesn't
authorBrett Cannon <brett@python.org>
Fri, 31 Aug 2012 15:31:20 +0000 (11:31 -0400)
committerBrett Cannon <brett@python.org>
Fri, 31 Aug 2012 15:31:20 +0000 (11:31 -0400)
return one.

Lib/test/test_imp.py

index 20e5608e81b54be626c5ab372c1cd237f2951760..65c9f25c8386dd362b9ead2f9ef8d45a0b99617d 100644 (file)
@@ -211,7 +211,9 @@ class ImportTests(unittest.TestCase):
         # and importlib couldn't handle C extensions
         example = "_heapq"
         x = imp.find_module(example)
-        self.addCleanup(x[0].close)
+        file_ = x[0]
+        if file_ is not None:
+            self.addCleanup(file_.close)
         mod = imp.load_module(example, *x)
         self.assertEqual(mod.__name__, example)