mirror of
https://github.com/python/cpython.git
synced 2025-09-19 07:00:59 +00:00
#18681: Fix a NameError in imp.reload() (noticed by Weizhao Li).
This commit is contained in:
parent
a9e67ad993
commit
056bafe7a6
3 changed files with 12 additions and 1 deletions
|
@ -267,7 +267,7 @@ def reload(module):
|
||||||
parent_name = name.rpartition('.')[0]
|
parent_name = name.rpartition('.')[0]
|
||||||
if parent_name and parent_name not in sys.modules:
|
if parent_name and parent_name not in sys.modules:
|
||||||
msg = "parent {!r} 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)
|
return module.__loader__.load_module(name)
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -275,6 +275,15 @@ class ReloadTests(unittest.TestCase):
|
||||||
import marshal
|
import marshal
|
||||||
imp.reload(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):
|
class PEP3147Tests(unittest.TestCase):
|
||||||
"""Tests of PEP 3147."""
|
"""Tests of PEP 3147."""
|
||||||
|
|
|
@ -64,6 +64,8 @@ Core and Builtins
|
||||||
Library
|
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
|
- Issue #8112: xlmrpc.server's DocXMLRPCServer server no longer raises an error
|
||||||
if methods have annotations; it now correctly displays the annotations.
|
if methods have annotations; it now correctly displays the annotations.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue