From: Brett Cannon Date: Mon, 12 Aug 2013 17:29:11 +0000 (-0400) Subject: Closes issue #18598: Have the exception message for X-Git-Tag: v3.4.0a2~244 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e1f159722e9767ccd28d13fc4cd6a18f7adfcc47;p=python 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. --- diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py index aab54a7f18..6732977a2b 100644 --- a/Lib/importlib/__init__.py +++ b/Lib/importlib/__init__.py @@ -85,7 +85,9 @@ def import_module(name, package=None): level = 0 if name.startswith('.'): if not package: - raise TypeError("relative imports require the 'package' argument") + msg = ("the 'package' argument is required to perform a relative " + "import for {!r}") + raise TypeError(msg.format(name)) for character in name: if character != '.': break diff --git a/Misc/NEWS b/Misc/NEWS index a9f2b8b330..15bee70749 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -24,6 +24,9 @@ Core and Builtins Library ------- +- Issue #18598: Tweak exception message for importlib.import_module() to + include the module name when a key argument is missing. + - Issue #18676: Change 'positive' to 'non-negative' in queue.py put and get docstrings and ValueError messages. Patch by Zhongyue Luo