]> granicus.if.org Git - python/commitdiff
#18681: Fix a NameError in imp.reload() (noticed by Weizhao Li).
authorEzio Melotti <ezio.melotti@gmail.com>
Sat, 10 Aug 2013 16:59:36 +0000 (19:59 +0300)
committerEzio Melotti <ezio.melotti@gmail.com>
Sat, 10 Aug 2013 16:59:36 +0000 (19:59 +0300)
Lib/imp.py
Lib/test/test_imp.py
Misc/NEWS

index 40869f5ac06c992fb274f280396f6a2f08e8fce5..34b6c542e1203fdcd8e99163af2ff067d3474363 100644 (file)
@@ -267,7 +267,7 @@ def reload(module):
         parent_name = name.rpartition('.')[0]
         if parent_name and parent_name not in sys.modules:
             msg = "parent {!r} not in sys.modules"
-            raise ImportError(msg.format(parentname), name=parent_name)
+            raise ImportError(msg.format(parent_name), name=parent_name)
         return module.__loader__.load_module(name)
     finally:
         try:
index fe436f3985012e3ed63502e2eab64574625e88d3..ade3e2564f3300716afb467d0366d9c9b3452794 100644 (file)
@@ -275,6 +275,15 @@ class ReloadTests(unittest.TestCase):
             import marshal
             imp.reload(marshal)
 
+    def test_with_deleted_parent(self):
+        # see #18681
+        from html import parser
+        del sys.modules['html']
+        def cleanup(): del sys.modules['html.parser']
+        self.addCleanup(cleanup)
+        with self.assertRaisesRegex(ImportError, 'html'):
+            imp.reload(parser)
+
 
 class PEP3147Tests(unittest.TestCase):
     """Tests of PEP 3147."""
index 635a925970f53b6198fd83464d88e1cfb9be165d..ccbb57a3b8632e737ef36bd737afacbee78d88cc 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -64,6 +64,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #18681: Fix a NameError in imp.reload() (noticed by Weizhao Li).
+
 - Issue #8112: xlmrpc.server's DocXMLRPCServer server no longer raises an error
   if methods have annotations; it now correctly displays the annotations.