Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 056bafe

Browse files
committed
#18681: Fix a NameError in imp.reload() (noticed by Weizhao Li).
1 parent a9e67ad commit 056bafe

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lib/imp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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:

Lib/test/test_imp.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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

279288
class PEP3147Tests(unittest.TestCase):
280289
"""Tests of PEP 3147."""

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ Core and Builtins
6464
Library
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

0 commit comments

Comments
 (0)