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

Skip to content

Commit e1f1597

Browse files
committed
Closes issue #18598: Have the exception message for
importlib.import_module() include the name of the module when the 'package' argument is missing but needed.
1 parent 388a392 commit e1f1597

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

Lib/importlib/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ def import_module(name, package=None):
8585
level = 0
8686
if name.startswith('.'):
8787
if not package:
88-
raise TypeError("relative imports require the 'package' argument")
88+
msg = ("the 'package' argument is required to perform a relative "
89+
"import for {!r}")
90+
raise TypeError(msg.format(name))
8991
for character in name:
9092
if character != '.':
9193
break

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Core and Builtins
2424
Library
2525
-------
2626

27+
- Issue #18598: Tweak exception message for importlib.import_module() to
28+
include the module name when a key argument is missing.
29+
2730
- Issue #18676: Change 'positive' to 'non-negative' in queue.py put and get
2831
docstrings and ValueError messages. Patch by Zhongyue Luo
2932

0 commit comments

Comments
 (0)