File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -267,7 +267,7 @@ def reload(module):
267267 parent_name = name .rpartition ('.' )[0 ]
268268 if parent_name and parent_name not in sys .modules :
269269 msg = "parent {!r} not in sys.modules"
270- raise ImportError (msg .format (parentname ), name = parent_name )
270+ raise ImportError (msg .format (parent_name ), name = parent_name )
271271 return module .__loader__ .load_module (name )
272272 finally :
273273 try :
Original file line number Diff line number Diff line change @@ -275,6 +275,15 @@ def test_builtin(self):
275275 import marshal
276276 imp .reload (marshal )
277277
278+ def test_with_deleted_parent (self ):
279+ # see #18681
280+ from html import parser
281+ del sys .modules ['html' ]
282+ def cleanup (): del sys .modules ['html.parser' ]
283+ self .addCleanup (cleanup )
284+ with self .assertRaisesRegex (ImportError , 'html' ):
285+ imp .reload (parser )
286+
278287
279288class PEP3147Tests (unittest .TestCase ):
280289 """Tests of PEP 3147."""
Original file line number Diff line number Diff line change @@ -64,6 +64,8 @@ Core and Builtins
6464Library
6565-------
6666
67+ - Issue #18681: Fix a NameError in imp.reload() (noticed by Weizhao Li).
68+
6769- Issue #8112: xlmrpc.server's DocXMLRPCServer server no longer raises an error
6870 if methods have annotations; it now correctly displays the annotations.
6971
You can’t perform that action at this time.
0 commit comments