summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/importlib/__init__.py2
-rw-r--r--Lib/test/test_imp.py9
2 files changed, 10 insertions, 1 deletions
diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py
index d456c48..aab54a7 100644
--- a/Lib/importlib/__init__.py
+++ b/Lib/importlib/__init__.py
@@ -115,7 +115,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:
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py
index cf50ea4..833bf19 100644
--- a/Lib/test/test_imp.py
+++ b/Lib/test/test_imp.py
@@ -314,6 +314,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."""