summaryrefslogtreecommitdiffstats
path: root/Lib/runpy.py
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-03-31 11:23:55 (GMT)
committerGitHub <noreply@github.com>2020-03-31 11:23:55 (GMT)
commitef67512b40240f765026ad41d60b0c9a6dacd2b9 (patch)
tree4cd0562ba5495f96213587b6bd2caeebd906b481 /Lib/runpy.py
parentc49016e67c3255b37599b354a8d7995d40663991 (diff)
downloadcpython-ef67512b40240f765026ad41d60b0c9a6dacd2b9.zip
cpython-ef67512b40240f765026ad41d60b0c9a6dacd2b9.tar.gz
cpython-ef67512b40240f765026ad41d60b0c9a6dacd2b9.tar.bz2
bpo-40108: Improve the error message in runpy when importing a module that includes the extension (GH-19239)
Diffstat (limited to 'Lib/runpy.py')
-rw-r--r--Lib/runpy.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/Lib/runpy.py b/Lib/runpy.py
index 0f54f3e..7e1e1ac 100644
--- a/Lib/runpy.py
+++ b/Lib/runpy.py
@@ -133,6 +133,9 @@ def _get_module_details(mod_name, error=ImportError):
# importlib, where the latter raises other errors for cases where
# pkgutil previously raised ImportError
msg = "Error while finding module specification for {!r} ({}: {})"
+ if mod_name.endswith(".py"):
+ msg += (f". Try using '{mod_name[:-3]}' instead of "
+ f"'{mod_name}' as the module name.")
raise error(msg.format(mod_name, type(ex).__name__, ex)) from ex
if spec is None:
raise error("No module named %s" % mod_name)